public void Container_Service_ShouldHandleNamedServices(Lifetime lifetime) { Assert.DoesNotThrow(() => Container .Service <IInterface_1, Implementation_1_No_Dep>("svc1", lifetime) .Service <IInterface_1, DecoratedImplementation_1>("svc2", lifetime)); Assert.IsNull(Container.Get <IInterface_1>()); Assert.IsNull(Container.Get <IInterface_1>("invalidname")); Assert.AreEqual(lifetime.CreateFrom(typeof(IInterface_1), "svc1", typeof(Implementation_1_No_Dep), Container).Where(entry => !entry.IsInternal()).Single(), Container.Get <IInterface_1>("svc1")); Assert.AreEqual(lifetime.CreateFrom(typeof(IInterface_1), "svc2", typeof(DecoratedImplementation_1), Container).Where(entry => !entry.IsInternal()).Single(), Container.Get <IInterface_1>("svc2")); }
public void Container_Factory_ShouldHandleNamedServices(Lifetime lifetime) { Func <IInjector, Type, IInterface_1> factory = (injector, type) => new Implementation_1_No_Dep(); Assert.DoesNotThrow(() => Container .Factory(typeof(IInterface_1), "svc1", factory, lifetime) .Factory(typeof(IInterface_1), "svc2", factory, lifetime)); Assert.IsNull(Container.Get <IInterface_1>()); Assert.IsNull(Container.Get <IInterface_1>("invalidname")); Assert.AreEqual(lifetime.CreateFrom(typeof(IInterface_1), "svc1", factory, Container).Where(entry => !entry.IsInternal()).Single(), Container.Get <IInterface_1>("svc1")); Assert.AreEqual(lifetime.CreateFrom(typeof(IInterface_1), "svc2", factory, Container).Where(entry => !entry.IsInternal()).Single(), Container.Get <IInterface_1>("svc2")); }