public void ConstrainsForOpenGenerics(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericService<>)); adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericServiceWithIService2Constraint<>)); var resolved = adapter.ResolveAll<IGenericService<IndependentService>>().ToArray(); Assert.Equal(1, resolved.Length); Assert.IsType<GenericService<IndependentService>>(resolved[0]); }
public void ConstrainsForOpenGenerics(IContainerAdapter adapter) { adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>)); adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericServiceWithIService2Constraint <>)); var resolved = adapter.ResolveAll <IGenericService <IndependentService> >().ToArray(); Assert.Equal(1, resolved.Length); Assert.IsType <GenericService <IndependentService> >(resolved[0]); }
public static IEnumerable <TService> ResolveAll <TService>(this IContainerAdapter container) { return(container.ResolveAll(typeof(TService)).Cast <TService>()); }