public void InstancePerJob_RegistersSameServiceInstance_ForTheSameScopeInstance() { container.RegisterType <object>( new HierarchicalLifetimeManager(), new InjectionFactory(c => new object())); var activator = CreateActivator(); using (var scope = new SimpleJobActivatorScope(activator)) { var instance1 = scope.Resolve(typeof(object)); var instance2 = scope.Resolve(typeof(object)); Assert.AreSame(instance1, instance2); } }
public void InstancePerBackgroundJob_RegistersDifferentServiceInstances_ForDifferentScopeInstances() { container.RegisterType <object>( new HierarchicalLifetimeManager(), new InjectionFactory(c => new object())); var activator = CreateActivator(); object instance1; using (var scope1 = new SimpleJobActivatorScope(activator)) { instance1 = scope1.Resolve(typeof(object)); } object instance2; using (var scope2 = new SimpleJobActivatorScope(activator)) { instance2 = scope2.Resolve(typeof(object)); } Assert.AreNotSame(instance1, instance2); }
public void InstancePerContainer_RegistersSameServiceInstance_ForDifferentScopeInstances() { container.RegisterType <object>( new ContainerControlledLifetimeManager(), new InjectionFactory(c => new object())); var activator = CreateActivator(); object instance1; using (var scope1 = new SimpleJobActivatorScope(activator)) { instance1 = scope1.Resolve(typeof(object)); } object instance2; using (var scope2 = new SimpleJobActivatorScope(activator)) { instance2 = scope2.Resolve(typeof(object)); } Assert.AreSame(instance1, instance2); }