温莎城堡类型工厂设施的等效产品 [英] Castle Windsor Typed Factory Facility equivalents

查看:86
本文介绍了温莎城堡类型工厂设施的等效产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何其他.NET IoC容器提供与温莎城堡中类型化工厂设施相同的功能?

do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor?

例如如果我在WPF应用程序中使用抽象工厂模式:

e.g. if I am using an abstract factory pattern in a WPF application:

public class MyViewModel
{
   private IAnotherViewModelFactory factory;

   public void ShowAnotherViewModel()
   {
      viewController.ShowView(factory.GetAnotherViewModel());
   }
}

我不想为我要显示的每种ViewModel类型创建IAnotherViewModelFactory的手动实现,我希望容器为我自己解决这个问题.

I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container to take care of this for me.

推荐答案

AutoFac具有称为代理工厂,但据我所知,它仅适用于代理,而不适用于接口.

AutoFac has a feature called Delegate Factories, but as far as I can tell, it works only with delegates, and not interfaces.

在StructureMap和Unity中,我都没有遇到过与Castle的类型化工厂设施类似的任何事情,但这并不一定意味着它们不存在...

I haven't encountered anything similar to Castle's Typed Factory Facility in neither StructureMap nor Unity, but that doesn't necessarily mean that they're not there...

我可以想象可以为接口实现类似功能的唯一方法是通过动态代理.由于Castle Windsor具有动态代理,但是很少有其他容器具有类似功能,因此这可能会很长一段路要解释为什么此功能并不普遍.

The only way I can imagine that something like this could be implemented for interfaces is via a dynamic proxy. Since Castle Windsor has a Dynamic Proxy, but few other containers have anything similar, this might go a long way to explain why this feature isn't ubiquitous.

Unity还提供了拦截功能,因此它必须具有某种动态代理实现,但是我很确定它没有等同于Typed Factories的任何东西.与其他容器相比,Unity非常基础.

Unity also offers interception capabilities, so it must have some sort of dynamic proxy implementation, but I'm pretty sure it doesn't have anything equivalent to Typed Factories. Compared to other containers, Unity is rather basic.

这篇关于温莎城堡类型工厂设施的等效产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆