/// <summary> /// Registers the type. /// </summary> /// <param name="serviceType">Type of the service.</param> /// <param name="implementationType">Type of the implementation.</param> /// <param name="lifetime">The lifetime of the service.</param> /// <returns></returns> public override IServiceRegistrar RegisterType(Type serviceType, Type implementationType, LifetimeType lifetime) { Invariant.IsNotNull(serviceType, "serviceType"); Invariant.IsNotNull(implementationType, "implementationType"); LifetimeManager lifeTimeManager; switch (lifetime) { case LifetimeType.PerRequest: lifeTimeManager = new PerRequestLifetimeManager(); break; case LifetimeType.Singleton: lifeTimeManager = new ContainerControlledLifetimeManager(); break; default: lifeTimeManager = new TransientLifetimeManager(); break; } if (Container.Registrations.Any(registration => registration.RegisteredType.Equals(serviceType))) { Container.RegisterType(serviceType, implementationType, implementationType.FullName, lifeTimeManager); } else { Container.RegisterType(serviceType, implementationType, lifeTimeManager); } return(this); }
private static void RemoveAllInstances() { IDictionary <PerRequestLifetimeManager, object> lifetimeManagers = GetPerRequestLifetimeManagers(); PerRequestLifetimeManager[] managers = new PerRequestLifetimeManager[lifetimeManagers.Count]; lifetimeManagers.Keys.CopyTo(managers, 0); managers.Each(lifetimeManager => lifetimeManager.RemoveValue()); lifetimeManagers.Clear(); }
private static void RemoveAllInstances() { IDictionary<PerRequestLifetimeManager, object> lifetimeManagers = GetPerRequestLifetimeManagers(); PerRequestLifetimeManager[] managers = new PerRequestLifetimeManager[lifetimeManagers.Count]; lifetimeManagers.Keys.CopyTo(managers, 0); managers.Each(lifetimeManager => lifetimeManager.RemoveValue()); lifetimeManagers.Clear(); }