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