You used the term 'injection', and based on your requirements, I would actually suggest taking look at using an IoC container (Spring, Windsor, Unity, etc.) instead as this would provide even greater flexibility. There's also some examples of this already:
I've encountered the requirement to make WCF service composeable many times, and the approach you identified where you use a custom IInstanceProvider is the way to solve it. Aswell as writing a custom instance provider, you also need a service behaviour, and a custom service host.
发布评论
评论(3)
您使用了术语“注入”,并且根据您的要求,我实际上建议考虑使用 IoC 容器(Spring、Windsor、Unity 等),因为这将提供更大的灵活性。 已经有一些这样的例子:
http://avingtonsolutions.com/blog/post/2008/08/02/Uisng-Unity-with-a-WCF-Service.aspx
You used the term 'injection', and based on your requirements, I would actually suggest taking look at using an IoC container (Spring, Windsor, Unity, etc.) instead as this would provide even greater flexibility. There's also some examples of this already:
http://avingtonsolutions.com/blog/post/2008/08/02/Uisng-Unity-with-a-WCF-Service.aspx
我多次遇到使 WCF 服务可组合的要求,您在使用自定义 IInstanceProvider 时确定的方法就是解决该问题的方法。 除了编写自定义实例提供程序之外,您还需要服务行为和自定义服务主机。
在代码示例方面,我在我的博客上记录了我的方法:
http://www.timjroberts.com/2011/08/wcf- services-with-mef/
希望这有帮助。
I've encountered the requirement to make WCF service composeable many times, and the approach you identified where you use a custom IInstanceProvider is the way to solve it. Aswell as writing a custom instance provider, you also need a service behaviour, and a custom service host.
In terms of code-samples, I've documented my approach on my blog:
http://www.timjroberts.com/2011/08/wcf-services-with-mef/
Hope this helps.
您可以使用此 nuget 包。 在项目站点,您可以找到几个如何在 Web 应用程序中使用该库或作为自托管服务的示例。
You can use this nuget package. At project site, you can find couple examples how to use the library in web application or as self hosted service.