繁体   English   中英

统一注册或添加为参考

[英]Register to unity or added as reference

我的应用程序中有3个模块。 和1个ServiceLibrary。

Module1
Module2
Module3

ServiceLibrary

Bootstrapper添加模块后,ServiceLibrary将注册到Unity,因此ServiceLibrary在Module1中注册到Unity。 喜欢:

_container.RegisterType<ISystemService>,ServiceLibrary>();

该服务也可以被所有其他模块调用。 因此,当它以Module2为例被调用时,它将像在Module2中那样解析并使用它:

ISytemService myserv=_container.Resolve<ISystemService>("ServiceLibrary");

那么哪种方法对性能好呢?

在需要使用该ServiceLibrary时,将其作为模块的引用添加到该模块中,或使用上述方法从Unity中解析该服务库。 在项目中,有100多个这样的服务库。

Module1,Module2,Module3和ServiceLibrary应该引用一个单独的程序集,该程序集包含IServiceLibrary和WellKnownService名称列表,并且应使用Unity获得具体实例:

ISytemService myserv=_container.Resolve<ISystemService>(WellKnownNames.ServiceLibrary);

在模块中将引用添加到ServiceLibrary消除了使用像Unity这样的IoC容器的全部要点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM