using Microsoft.Practices.Unity;
public static void Main()
var ioc = new UnityContainer();
ioc.RegisterType(typeof(I<>), new OpenGenericTypeFactory(typeof(I<>), typeof(C<>)));
var c = ioc.Resolve<I<double>>();
Console.WriteLine(c.GetType());
class OpenGenericTypeFactory : Microsoft.Practices.Unity.InjectionFactory {
public OpenGenericTypeFactory(Type from, Type to)
: base((container, type, _) => Create(container, from, to, type))
private static object Create(IUnityContainer container, Type fromType, Type toType, Type requestedType)
if (!requestedType.IsGenericType || requestedType.GetGenericTypeDefinition() != fromType)
throw new Exception($"Injection factory for {fromType}: got type {requestedType} instead.");
Type[] argTypes = requestedType.GetGenericArguments();
var closedGenericTarget = toType.MakeGenericType(argTypes);
return container.Resolve(closedGenericTarget);
throw new Exception($"Failed to resolve type {closedGenericTarget} for requested type {requestedType}");