// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { _logger.Trace("Configuring service..."); // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); var scope = AutoFacCore.InitScope(new MainModule(), new WebModule()); appBuilder.Use <GlobalExceptionMiddleware>(); appBuilder.Use((context, next) => { if (HttpContext.Current != null) { HttpContext.Current.Response.SuppressFormsAuthenticationRedirect = true; } return(next.Invoke()); }); config.DependencyResolver = new AutofacWebApiDependencyResolver(scope); appBuilder.UseAutofacMiddleware(scope); appBuilder.UseWebApi(config); }
private static RssService GetService() { var serviceName = GetServiceNameFromConfiguration(); string hostName = ConfigurationManager.AppSettings["Host"]; int port = ConfigurationManager.AppSettings["Port"].ToInt(); bool useSsl = ConfigurationManager.AppSettings["UseSsl"].ToBoolean(); var scope = AutoFacCore.InitScope(new MainModule()); var jobLauncher = scope.Resolve <JobLauncher>(); return(new RssService(serviceName, $"http{(useSsl ? "s" : "")}://{hostName}:{port}", jobLauncher)); }
public IScheduler Create() { try { // Get a reference to the scheduler var sf = new StdSchedulerFactory(); var scheduler = sf.GetScheduler(); var scope = AutoFacCore.InitScope(_module); scheduler.JobFactory = new AutoFacJobFactory(scope); return(scheduler); } catch (Exception ex) { _logger.Fatal("Scheduler not available: '{0}'", ex.Message); throw; } }