English 中文(简体)
Equivalent of Bind<>. ToMethod in Unity?
原标题:Equivalent of Bind<>.ToMethod in Unity?

是否在团结中存在类似Ninject工厂方法? I m 寻求以下范例的团结:

Bind<IWeapon>().ToMethod(context => new Sword());
最佳回答

是的,注射法:

container.RegisterType<IWeapon>(
    new InjectionFactory(con => new Sword());

当然,在这种特定情况下,我将不使用该集装箱,因为集装箱的违约行为将用简单的类型制图来做到这一点。 我假定你的实际代表比较复杂。

问题回答

暂无回答




相关问题
Unity (in PRISM) does (not) weird resolving...??!!

I m using PRISM and in the Bootstrapper class i did override the ConfigureContainer() method. There is nothing fancy in it just these lines: protected override void ConfigureContainer() { ...

Unity Configuration and Same Assembly

I m currently getting an error trying to resolve my IDataAccess class. The value of the property type cannot be parsed. The error is: Could not load file or assembly TestProject or one of its ...

Unity IOC, AOP & Interface Interception

I ve been playing around with Unity to do some AOP stuff, setting up via IOC like: ioc.RegisterType<ICustomerService, CustomerService>() .Configure<Interception>().SetInterceptorFor&...

How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like ...

Unity view Registered Types during debug

Possibly a stupid question, but during debug I simply want to see the types that have been registered with my Unity container. I have tried going through the container in the watch window, but can t ...

Unity constructors

I have setup unity in my project and it is working for objects that don t have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a ...

StrucutureMap RhinoMock Record/Playback, Example needed

I m looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

热门标签