简体   繁体   English

如何在使用Common Service Factory时初始化容器

[英]How do I initialize my container when using the Common Service Factory

The Common Service Factory website specifies the following steps for its usage: Common Service Factory网站指定了以下使用步骤:

  • Download the latest release of the Common Service Factory library 下载最新版本的Common Service Factory库
  • Download the latest release of the Common Service Locator library and the adapter for the IoC container that you are using 下载最新版本的Common Service Locator库和适用于您正在使用的IoC容器的适配器
  • Add a reference to the CommonServiceFactory.dll, Microsoft.Practices.ServiceLocation.dll and the assembly that contains the adapter for your IoC container 添加对CommonServiceFactory.dll,Microsoft.Practices.ServiceLocation.dll以及包含IoC容器适配器的程序集的引用
  • Edit the .svc file for your service so that Service attribute contains the Assembly-Qualified Name of the service type 编辑服务的.svc文件,以便Service属性包含服务类型的Assembly-Qualified Name
  • In the .svc file, add the Factory attribute and provide the Assembly-Qualified Name of on of the factories that are available (ServiceHostFactory for SOAP services and WebServiceHostFactory for RESTful services) in the Common Service Factory library 在.svc文件中,添加Factory属性,并在Common Service Factory库中提供可用工厂(SOAP服务的ServiceHostFactory和RESTful服务的WebServiceHostFactory)的程序集限定名称。
  • Configure your IoC and setup the Common Service Adapter 配置IoC并设置公共服务适配器
  • Enjoy using loosely coupled dependencies in your WCF services using the IoC container you prefer 使用您喜欢的IoC容器,享受在WCF服务中使用松散耦合的依赖项

I just don't know where should I do the second to last step: Configure your IOC and setup the Common Service Adapter. 我只是不知道从哪里开始倒数第二步:配置您的IOC并设置公共服务适配器。

Does anyone has an example of how to use the Common Service Factory? 有没有人有一个如何使用公共服务工厂的例子?

Thanks a lot. 非常感谢。

You typically setup your container in the startup path of your application. 您通常在应用程序的启动路径中设置容器。 For a ASP.NET application for instance, this would typically be the Application_Start event. 例如,对于ASP.NET应用程序,这通常是Application_Start事件。 After you created the container, you wrap the container into a Common Service Locator adapter for the given container and supply it to the ServiceLocator.SetLocatorProvider of the CSL project and you're done. 在创建容器之后,将容器包装到给定容器的Common Service Locator适配器中,并将其提供给CSL项目的ServiceLocator.SetLocatorProvider ,您就完成了。

This is how it looks like when using Simple Injector: 这是使用Simple Injector时的样子:

var adapter = 
    new SimpleInjectorServiceLocatorAdapter(container);

ServiceLocator.SetLocatorProvider(() => adapter);

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

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