private static ILifetime ResolveLifetime(ServiceDescriptor serviceDescriptor) { if (serviceDescriptor.ImplementationInstance != null) { return(null); } ILifetime lifetime = null; switch (serviceDescriptor.Lifetime) { case ServiceLifetime.Scoped: lifetime = new PerScopeLifetime(); break; case ServiceLifetime.Singleton: lifetime = new PerContainerLifetime(); break; case ServiceLifetime.Transient: lifetime = new PerRequestLifeTime(); break; } return(lifetime); }
public void ShouldClonePerRequestLifetime() { var lifetime = new PerRequestLifeTime(); var clone = lifetime.Clone(); Assert.IsType <PerRequestLifeTime>(clone); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Load the configuration ConfigurationService.Load(); // Log the application initialization LogService.Debug("Lidia Scheduler UI initialized"); // Hangfire HangfireBootstrapper.Instance.Start(); // Register the main job RecurringJob.AddOrUpdate("Daily Job Registration", () => HangfireService.UpdateJobs(), Cron.Daily); #region [ Dependency Injection ] // Create the container as usual. var container = new ServiceContainer(); var lifeTime = new PerRequestLifeTime(); // Register your types, for instanceScoped); container.Register <ITenantService, TenantService>(lifeTime); container.Register <IUserService, UserService>(lifeTime); container.Register <ISchedulerService, SchedulerService>(lifeTime); container.RegisterControllers(); container.EnableMvc(); #endregion }