2011-11-01 30 views
2

即时尝试获得毫秒统一注入一个对象到构造函数和我有问题,由于有多个构造函数和相同数量的参数的类。我知道你可以注释构造函数,但我不想那样做。我怎样才能得到统一使用正确的构造毫秒统一和多个构造函数

我的构造就像这样: -

public JobsHandler(ICentralRepositoryContainer context) 
    public JobsHandler(ICentralRepositoryLifeTimehelper centralRepositoryLifeTimehelper) 

和我使用一些代码,我发现: -

uContainer.RegisterType<ICentralRepositoryContainer, Entities>().Configure<InjectedMembers>(). 
      ConfigureInjectionFor<JobsHandler>(new InjectionConstructor()); 

但在得到一个

CentralRepository.BusinessLogic.JobsHandler类型没有 构造函数,它需要t他参数()

我猜这是因为我还没有指定在injectionconstructor对象中的参数。我是否正确地做了这件事?

回答

2

我想你会想解决ICentralRepositoryContainer并在InjectionConstructor

uContainer.RegisterType<ICentralRepositoryContainer, Entities>().Configure<InjectedMembers>().ConfigureInjectionFor<JobsHandler>(
    new InjectionConstructor(new ResolvedParameter(typeof(ICentralRepositoryContainer))); 

使用它,或者同时指定构造函数注册的作业处理程序。

uContainer.RegisterType<ICentralRepositoryContainer, Entities>(); 
uContainer.RegisterType<JobsHandler>(new InjectionConstructor(new ResolvedParameter(typeof(ICentralRepositoryContainer)))); 

请参阅此链接上面的一个更完整的例子:

http://msdn.microsoft.com/en-us/library/ff650036.aspx

+0

是不工作。 ConfigureInjectionFor不是容器的成员 –

+0

我的道歉。我的意思是使用RegisterType方法。我已经赞扬了上述内容,并使用您的原始方法添加了一个示例。 P.S.我不能100%确定这是否可行,因为我目前无法验证它。但我认为这大致是你需要做的。 – Balthy