Reputation: 15378
I use 3-party library and I want to invoke custom constructor extend of empty constructor.
I use structuremap.
Is it possible ?
Source code from 3-party library:
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]);
}
I tried
x.For<IJobFactory>().Use<StructureMapJobFactory>();
x.ForConcreteType<StructureMapJobFactory>().Configure.SelectConstructor(() => new StructureMapJobFactory(container.GetInstance<IContext>()));
Upvotes: 0
Views: 103
Reputation: 14995
you can use this :
public static T InstantiateType<T>() where T : new()
{
return new T();
}
Upvotes: 1