public void SetValue(object newValue) { // Unity will now track and dispose this object when the request has ended. var perRequestLifetimeManager = new PerRequestLifetimeManager(); perRequestLifetimeManager.SetValue(newValue); }
public void SetValue(object newValue) { // No point in saving to http context if not disposable if (newValue is IDisposable) { var perRequestLifetimeManager = new PerRequestLifetimeManager(); perRequestLifetimeManager.SetValue(newValue); } }
/// <summary> /// Creates an instance of UnityContainer and registers the instances which needs to be injected /// to Controllers/Views/Services, etc. /// </summary> private static void RegisterUnityContainer() { _container = new UnityContainer(); var earthSettings = ConfigReader<string>.GetSetting("EarthOnlineEntities"); var manager = new PerRequestLifetimeManager(); var constructor = new InjectionConstructor(earthSettings); _container.RegisterType<EarthOnlineEntities>(manager,constructor); RegisterRepositories(_container); RegisterServices(_container); DependencyResolver.SetResolver(new UnityDependencyResolver(_container)); }
LifetimeManager GetLifetimeManager(Type lifeTimeType) { LifetimeManager lifetimeManager; if (KnownTypes.SingleInstanceType.IsAssignableFrom(lifeTimeType)) { lifetimeManager = new ContainerControlledLifetimeManager(); } else if (KnownTypes.PerRequestType.IsAssignableFrom(lifeTimeType)) { lifetimeManager = new PerRequestLifetimeManager(); } else { lifetimeManager = new PerResolveLifetimeManager(); } return lifetimeManager; }
public PerRequestLifetimeManagerTests() { lifetimeManager = new PerRequestLifetimeManager(); }
/// <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; }