/// <summary> /// The register types. /// </summary> /// <param name="options"> /// The options. /// </param> /// <returns> /// The <see cref="ContainerBuilder"/>. /// </returns> public static ContainerBuilder RegisterTypes(IDeploymentServerOptions options) { var containerBuilder = new ContainerBuilder(); RegisterTypes(options, containerBuilder); return(containerBuilder); }
/// <summary> /// The use deployment server. /// </summary> /// <param name="app"> /// The app. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="componentOptions"> /// The component options. /// </param> /// <returns> /// The <see cref="IAppBuilder"/>. /// </returns> public static IAppBuilder UseDeploymentServer( this IAppBuilder app, IDeploymentServerOptions options, IDscComponentOptions componentOptions) { return(UseDeploymentServer(app, "/api/v2", options, componentOptions)); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationService"/> class. /// </summary> /// <param name="eventManager"> /// The event manager. /// </param> /// <param name="context"> /// The context. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="logging"> /// The logging. /// </param> public ConfigurationService( IDscEventManager eventManager, DeploymentServerContext context, IDeploymentServerOptions options, IDeploymentServerLogging logging) : base(eventManager) { this.Context = context; this.Repository = context.Set <Configuration>(); this.Options = options; this.Logging = logging; }
/// <summary> /// Initializes a new instance of the <see cref="MofBuilderService"/> class. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="runner"> /// The runner. /// </param> /// <param name="configurationService"> /// The configuration service. /// </param> /// <param name="monitoringApi"> /// The monitoring api. /// </param> /// <param name="logging"> /// The logging. /// </param> public MofBuilderService( DeploymentServerContext context, IDeploymentServerOptions options, IPowerShellRunner runner, IConfigurationService configurationService, IMonitoringApi monitoringApi, IDeploymentServerLogging logging) { this.Context = context; this.BuildRepository = context.Set <Build>(); this.Logging = logging; this.Options = options; this.Runner = runner; this.ConfigurationService = configurationService; this.MonitoringApi = monitoringApi; }
/// <summary> /// The register types. /// </summary> /// <param name="options"> /// The options. /// </param> /// <param name="containerBuilder"> /// The container builder. /// </param> public static void RegisterTypes(IDeploymentServerOptions options, ContainerBuilder containerBuilder) { // Infrastructure containerBuilder.Register(c => new DeploymentServerContext(options.NameOrConnectionString)) .As <DeploymentServerContext>(); containerBuilder.RegisterType <DeploymentServerContextInitializer>().AsSelf().AsImplementedInterfaces(); // containerBuilder.RegisterInstance(options.Logging).AsImplementedInterfaces(); containerBuilder.RegisterInstance(options).AsImplementedInterfaces(); // Services containerBuilder.RegisterType <MofBuilderService>().AsSelf().AsImplementedInterfaces(); containerBuilder.RegisterType <ConfigurationService>().AsImplementedInterfaces(); containerBuilder.Register(c => new PowerShellRunner(null)).AsImplementedInterfaces(); // Hangfire containerBuilder.Register(c => JobStorage.Current.GetMonitoringApi()) .As <IMonitoringApi>() .AsSelf() .AsImplementedInterfaces() .SingleInstance(); }
/// <summary> /// The register deployment server types. /// </summary> /// <param name="containerBuilder"> /// The container builder. /// </param> /// <param name="options"> /// The options. /// </param> public static void RegisterDeploymentServerTypes( this ContainerBuilder containerBuilder, IDeploymentServerOptions options) { RegisterTypes(options, containerBuilder); }
/// <summary> /// The use deployment server. /// </summary> /// <param name="app"> /// The app. /// </param> /// <param name="controllerPrefix"> /// The controller prefix. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="componentOptions"> /// The component options. /// </param> /// <returns> /// The <see cref="IAppBuilder"/>. /// </returns> public static IAppBuilder UseDeploymentServer( this IAppBuilder app, string controllerPrefix, IDeploymentServerOptions options, IDscComponentOptions componentOptions) { return(app.Map( controllerPrefix, builder => { var config = new HttpConfiguration(); // Set up DI var containerBuilder = RegisterTypes(options); var container = containerBuilder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); // Logging var optionsLogging = options.Logging ?? new DeploymentServerLogging(); var logging = container.IsRegistered <IDeploymentServerLogging>() ? container.Resolve <IDeploymentServerLogging>() : optionsLogging; // Initialize database MigrationsContextFactory.NameOrConnectionString = options.NameOrConnectionString; Database.SetInitializer(new DeploymentServerContextInitializer(logging)); var context = container.Resolve <DeploymentServerContext>(); context.Database.Initialize(true); context.Dispose(); // Configure HangFire DB GlobalConfiguration.Configuration.UseSqlServerStorage(options.NameOrConnectionString); // Configure HangFire GlobalConfiguration.Configuration.UseAutofacActivator(container); builder.UseHangfireServer( new BackgroundJobServerOptions { Queues = new[] { "mofbuilder", "default" }, WorkerCount = options.WorkerCount }); if (options.UseJobDashbaord) { app.UseHangfireDashboard(); } // Configure cleanup jobs SetupDbMaintenance(); // Set up filters config.Filters.Add(new AuthorizeAttribute()); config.MessageHandlers.Add(new UrlHelperHandler(container.ComponentRegistry)); if (componentOptions.UsePrettyHtmlOutput) { config.Formatters.Add(new JsonTextMediaFormatter()); } // Map routes and formatting config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; config.IncludeErrorDetailPolicy = componentOptions.ErrorDetailPolicy; config.MapHttpAttributeRoutes(); builder.UseAutofacMiddleware(container); builder.UseAutofacWebApi(config); builder.UseWebApi(config); })); }