我在我的解决方案多个项目:注册界面在Unity基于容器的标记接口,为不同的生命周期上
Core
Repository
Service
WebAPi
我的统一登记上的WebAPI项目。
我想实现的东西我已经在温莎城堡在过去所做的,现在我想这样做,通过Unity:使用约定https://github.com/castleproject/Windsor/blob/master/docs/registering-components-by-conventions.md
我有两个标记接口寄存器接口。
public interface ISingletonDependency{}
public interface ITransientDependency{}
对于我的仓库或服务类我做的:
public interface IPersonRepository:ISingletonDependency{
...
...
}
public class PersonRepository: IPersonRepository{
...
...
...
}
在我的服务类:
public interface IPersonService:ISingletonDependency{
...
...
}
public class PersonService: IPersonService{
...
...
...
}
我在DI和类似的方式做到这一点对所有我的班在注册期间,我曾经这样做:
container.Register(
Classes.NamedAssembly("SolutionName.Repository")
.BasedOn<ISingletonDependency>()
.WithService.FromInterface().LifestyleSingleton()
);
container.Register(
Classes.NamedAssembly("SolutionName.Service")
.BasedOn<ISingletonDependency>()
.WithService.FromInterface().LifestyleSingleton()
);
container.Register(
Classes.NamedAssembly("SolutionName.Repository")
.BasedOn<ITransientDependency>()
.WithService.FromInterface().LifestyleTansient()
);
container.Register(
Classes.NamedAssembly("SolutionName.Service")
.BasedOn<ITransientDependency>()
.WithService.FromInterface().LifestyleTansient()
);
这种方式我不需要为每个人都做到这一点,我看到了Unity的方法,但它的确基于命名约定 ,您无法单独指定单身或瞬间生活方式。
https://blogs.msdn.microsoft.com/agile/2013/03/12/unity-configuration-registration-by-convention/
有没有办法做到,你可以在温莎城堡做什么,在我给,基于标记的接口上面的例子?
'我已经在温莎城堡进行的过去,现在我想通过Unity这样做.. 。 - 为什么你要从一个完全支持的DI容器移动到一个死的*容器? Unity [不再支持](https://github.com/unitycontainer/unity/issues),甚至当它在功能上严重落后时。微软[放弃了对它的支持](https://blogs.msdn.microsoft.com/dotnet/2015/08/21/the-future-of-unity/),但新的所有者不在意支持它要么 - 一年半没有承诺。 – NightOwl888
+100对于@ NightOwl888的评论:) – Steven