0
我使用3方库并且我想调用自定义构造函数的空构造函数。如何使用IoC作为空构造函数
我使用结构图。
可能吗?从3方库
的源代码:
public static T InstantiateType<T>(Type type)
{
if (type == null)
{
throw new ArgumentNullException("type", "Cannot instantiate null");
}
ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
if (ci == null)
{
throw new ArgumentException("Cannot instantiate type which has no empty constructor", type.Name);
}
return (T) ci.Invoke(new object[0]);
}
我试图
x.For<IJobFactory>().Use<StructureMapJobFactory>();
x.ForConcreteType<StructureMapJobFactory>().Configure.SelectConstructor(() => new StructureMapJobFactory(container.GetInstance<IContext>()));
请问你的代码的工作?如果不是,会发生什么? –
另外,你想实例化'T'还是'type'? –
嗯..我不知道,我认为类型。我设置了正确的类型,但我需要通过NOT空构造函数创建 – Mediator