예제 #1
0
        public static NaosServicesContextOptions AddQueueing(
            this NaosServicesContextOptions naosOptions,
            Action <QueueingOptions> optionsAction = null,
            string section = "naos:queueing")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // needed for mediator
            naosOptions.Context.Services.Scan(scan => scan
                                              .FromApplicationDependencies()
                                              .AddClasses(classes => classes.Where(c => c.Name.EndsWith("QueueEventHandler")))
                                              //.FromAssembliesOf(typeof(QueueEventHandler<>))
                                              //.AddClasses()
                                              .AsImplementedInterfaces());

            //naosOptions.Context.Services.AddSingleton<IHostedService>(sp =>
            //    new QueueProcessHostedService<T>(sp.GetRequiredService<ILoggerFactory>(), null));

            naosOptions.Context.Messages.Add($"{LogEventKeys.Startup} naos services builder: queueing added"); // TODO: list available commands/handlers
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Queueing", EchoRoute = "api/echo/queueing"
            });

            return(naosOptions);
        }
예제 #2
0
        public static NaosServicesContextOptions AddQueueing(
            this NaosServicesContextOptions naosOptions,
            Action <QueueingOptions> optionsAction = null,
            string section = "naos:queueing")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // needed for mediator
            naosOptions.Context.Services.Scan(scan => scan
                                              .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                                              .AddClasses(classes => classes.Where(c => c.Name.EndsWith("QueueEventHandler", StringComparison.OrdinalIgnoreCase)))
                                              //.FromAssembliesOf(typeof(QueueEventHandler<>))
                                              //.AddClasses()
                                              .AsImplementedInterfaces());

            optionsAction?.Invoke(new QueueingOptions(naosOptions.Context));

            naosOptions.Context.Messages.Add("naos services builder: queueing added"); // TODO: list available commands/handlers
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Queueing", EchoRoute = "naos/queueing/echo"
            });

            return(naosOptions);
        }
예제 #3
0
        /// <summary>
        /// Adds required services to support the service context functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        /// <returns></returns>
        public static NaosServicesContextOptions AddServiceContext(
            this NaosServicesContextOptions naosOptions)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            if (naosOptions.Context.Descriptor.Product.IsNullOrEmpty())
            {
                throw new NaosException("SERVICE descriptor needs a productName");
            }

            if (naosOptions.Context.Descriptor.Capability.IsNullOrEmpty())
            {
                throw new NaosException("SERVICE descriptor needs a capabilityName");
            }

            naosOptions.Context.Services.AddTransient <HttpClientServiceContextHandler>();
            naosOptions.Context.Services.AddSingleton(sp =>
                                                      new Naos.Core.Common.ServiceDescriptor(
                                                          naosOptions.Context.Descriptor.Product,
                                                          naosOptions.Context.Descriptor.Capability,
                                                          naosOptions.Context.Descriptor.Version,
                                                          naosOptions.Context.Descriptor.Tags));

            naosOptions.Context.Messages.Add($"{LogKeys.Startup} naos services builder: service context added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "ServiceContext", EchoRoute = "api/echo/servicecontext"
            });

            return(naosOptions);
        }
예제 #4
0
        public static NaosServicesContextOptions AddMessaging(
            this NaosServicesContextOptions naosOptions,
            Action <MessagingOptions> optionsAction = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services.Scan(scan => scan // https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
                                              .FromExecutingAssembly()
                                              .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                                              .AddClasses(classes => classes.AssignableTo(typeof(IMessageHandler <>)), true));

            naosOptions.Context.Services.AddSingleton <Hosting.IHostedService>(sp =>
                                                                               new MessagingHostedService(sp.GetRequiredService <ILogger <MessagingHostedService> >(), sp));
            naosOptions.Context.Services.AddSingleton <ISubscriptionMap, SubscriptionMap>();

            optionsAction?.Invoke(new MessagingOptions(naosOptions.Context));

            //context.Messages.Add($"{LogEventKeys.General} naos services builder: messaging added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Messaging", EchoRoute = "naos/messaging/echo"
            });

            return(naosOptions);
        }
예제 #5
0
        /// <summary>
        /// Adds required services to support the command handling functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        /// <param name="optionsAction"></param>
        /// <returns></returns>
        public static NaosServicesContextOptions AddCommands(
            this NaosServicesContextOptions naosOptions,
            Action <CommandsOptions> optionsAction = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services
            .Scan(scan => scan     // https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
                  .FromExecutingAssembly()
                  .FromApplicationDependencies(a => !a.FullName.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) && !a.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase))
                  .AddClasses(classes => classes.AssignableTo(typeof(ICommandBehavior)), true));

            naosOptions.Context.Messages.Add($"{LogEventKeys.Startup} naos services builder: commands added"); // TODO: list available commands/handlers

            optionsAction?.Invoke(new CommandsOptions(naosOptions.Context));
            //naosOptions.Context.Services
            //    .AddSingleton<ICommandBehavior, ValidateCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, TrackCommandBehavior>()
            //    //.AddSingleton<ICommandBehavior, ServiceContextEnrichCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, IdempotentCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, PersistCommandBehavior>();

            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Commands"
            });

            return(naosOptions);
        }
예제 #6
0
        public static NaosServicesContextOptions AddOidcAuthentication(
            this NaosServicesContextOptions naosOptions,
            Action <AuthenticationHandlerOptions> options = null,
            string section = "naos:authentication:oidc")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));

            var configuration  = naosOptions.Context.Configuration.GetSection(section).Get <OidcConfiguration>();
            var handlerOptions = new AuthenticationHandlerOptions();

            options?.Invoke(handlerOptions);

            naosOptions.Context.Services.AddAuthentication(options =>
            {
                options.DefaultScheme          = AuthenticationKeys.CookiesScheme;
                options.DefaultChallengeScheme = AuthenticationKeys.OidcScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                options.Authority                     = configuration.Authority;
                options.ClientId                      = configuration.ClientId;
                options.ClientSecret                  = configuration.ClientSecret;
                options.SaveTokens                    = true;
                options.ResponseType                  = IdentityModel.Protocols.OpenIdConnect.OpenIdConnectResponseType.Code; // configuration.ResponseType;
                options.RequireHttpsMetadata          = false;                                                                // dev only
                options.GetClaimsFromUserInfoEndpoint = true;
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("email");
                options.Scope.Add("claims");
                options.SaveTokens = true;
                //options.Events = new OpenIdConnectEvents
                //{
                //    OnTokenResponseReceived = async ctx =>
                //    {
                //        var a = ctx.Principal;
                //    },
                //    OnAuthorizationCodeReceived = async ctx =>
                //    {
                //        var a = ctx.Principal;
                //    }
                //};

                options.TokenValidationParameters = new IdentityModel.Tokens.TokenValidationParameters
                {
                    NameClaimType  = "name",
                    RoleClaimType  = "groups",
                    ValidateIssuer = true
                };
            });
            naosOptions.Context.Services.AddAuthorization();

            naosOptions.Context.Messages.Add($"naos services builder: authentication added (type={AspNetCore.Authentication.OpenIdConnect.OpenIdConnectDefaults.AuthenticationScheme})");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Authentication", Description = AspNetCore.Authentication.OpenIdConnect.OpenIdConnectDefaults.AuthenticationScheme, EchoRoute = "naos/authentication/echo"
            });

            return(naosOptions);
        }
예제 #7
0
        public static NaosServicesContextOptions AddEasyAuthentication(
            this NaosServicesContextOptions naosOptions,
            Action <AuthenticationHandlerOptions> options = null,
            string section = "naos:authentication:easyauth")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));

            var configuration  = naosOptions.Context.Configuration.GetSection(section).Get <EasyAuthConfiguration>();
            var handlerOptions = new AuthenticationHandlerOptions();

            options?.Invoke(handlerOptions);

            naosOptions.Context.Services
            .AddAuthorization()
            .AddScoped <IPolicyEvaluator>(sp => new EasyAuthPolicyEvaluator(
                                              sp.GetRequiredService <IAuthorizationService>(),
                                              handlerOptions.Provider.EmptyToNull() ?? configuration.Provider.EmptyToNull() ?? EasyAuthProviders.AzureActiveDirectory))
            .AddAuthentication(AuthenticationKeys.EasyAuthScheme)
            .AddEasyAuth(options);

            naosOptions.Context.Messages.Add($"naos services builder: authentication added (type={AuthenticationKeys.EasyAuthScheme})");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Authentication", Description = "EasyAuth", EchoRoute = "naos/authentication/echo"
            });

            return(naosOptions);
        }
예제 #8
0
        /// <summary>
        /// Adds required services to support the exception handling functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        /// <param name="hideDetails"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static NaosServicesContextOptions AddServiceExceptions(
            this NaosServicesContextOptions naosOptions,
            bool hideDetails = false,
            ExceptionHandlerMiddlewareOptions options = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services
            .AddSingleton(options ?? new ExceptionHandlerMiddlewareOptions()
            {
                HideDetails = hideDetails
            })
            .Scan(scan => scan     // https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
                  .FromExecutingAssembly()
                  .FromApplicationDependencies(a => !a.FullName.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) && !a.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase))
                  .AddClasses(classes => classes.AssignableTo(typeof(IExceptionResponseHandler)), true)
                  .AsSelfWithInterfaces()
                  .WithSingletonLifetime())

            // disable automatic modelstate validation (due to AddNaosExceptionHandling), as we validate it ourselves (app.exceptions.web) and have nicer exceptions
            .Configure <ApiBehaviorOptions>(o =>
            {
                o.SuppressModelStateInvalidFilter = true;
            });

            naosOptions.Context.Messages.Add($"{LogKeys.Startup} naos services builder: service exceptions added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "ServiceExceptions"
            });

            return(naosOptions);
        }
예제 #9
0
        public static NaosServicesContextOptions AddServiceClient(this NaosServicesContextOptions naosOptions, string name = "default", Action <IHttpClientBuilder> setupAction = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));
            EnsureArg.IsNotNullOrEmpty(name, nameof(name));

            naosOptions.Context.AddServiceClient(name, setupAction);

            return(naosOptions);
        }
예제 #10
0
        public static NaosServicesContextOptions AddServiceClient <TClient>(this NaosServicesContextOptions naosOptions, Action <IHttpClientBuilder> setupAction = null)
            where TClient : ServiceDiscoveryClient
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.AddServiceClient <TClient>(setupAction);

            return(naosOptions);
        }
예제 #11
0
        public static NaosServicesContextOptions AddServices(
            this NaosServicesContextOptions naosOptions,
            Action <ServiceOptions> optionsAction = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            optionsAction?.Invoke(new ServiceOptions(naosOptions.Context));

            return(naosOptions);
        }
예제 #12
0
        /// <summary>
        /// Adds required services to support the request filtering functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        public static NaosServicesContextOptions AddRequestFiltering(
            this NaosServicesContextOptions naosOptions)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services.TryAddSingleton <IFilterContextAccessor, FilterContextAccessor>();
            naosOptions.Context.Services.TryAddTransient <IFilterContextFactory, FilterContextFactory>();

            naosOptions.Context.Messages.Add("naos services builder: request filtering added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "RequestFiltering", EchoRoute = "naos/requestfiltering/echo?q=name=eq:naos,epoch=lt:12345&order=name"
            });

            return(naosOptions);
        }
예제 #13
0
        /// <summary>
        /// Adds required services to support the request correlation functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        public static NaosServicesContextOptions AddRequestCorrelation(
            this NaosServicesContextOptions naosOptions)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services.TryAddSingleton <ICorrelationContextAccessor, CorrelationContextAccessor>();
            naosOptions.Context.Services.TryAddTransient <ICorrelationContextFactory, CorrelationContextFactory>();
            naosOptions.Context.Services.AddTransient <HttpClientCorrelationHandler>();

            naosOptions.Context.Messages.Add("naos services builder: request correlation added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "RequestCorrelation", EchoRoute = "naos/requestcorrelation/echo"
            });

            return(naosOptions);
        }
예제 #14
0
        public static NaosServicesContextOptions AddServiceDiscoveryRouter(
            this NaosServicesContextOptions naosOptions,
            Action <ServiceDiscoveryRouterOptions> optionsAction = null,
            string section = "naos:serviceDiscovery")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services.AddProxy(o =>
            {
                //o.ConfigurePrimaryHttpMessageHandler(c => c.GetRequiredService<HttpClientLogHandler>());
                //o.AddHttpMessageHandler<HttpClientLogHandler>();
            });

            optionsAction?.Invoke(new ServiceDiscoveryRouterOptions(naosOptions.Context));

            return(naosOptions);
        }
예제 #15
0
        public static NaosServicesContextOptions AddOperations(
            this NaosServicesContextOptions naosOptions,
            Action <OperationsOptions> optionsAction = null,
            string section = "naos:operations")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            optionsAction?.Invoke(new OperationsOptions(naosOptions.Context));

            naosOptions.Context.Services.AddScoped <ILogEventService, LogEventService>();

            naosOptions.Context.Messages.Add($"{LogKeys.Startup} naos services builder: operations added");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Operations"
            });

            return(naosOptions);
        }
예제 #16
0
        public static NaosServicesContextOptions AddServiceDiscovery(
            this NaosServicesContextOptions naosOptions,
            Action <ServiceDiscoveryOptions> optionsAction = null,
            string section = "naos:serviceDiscovery")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            naosOptions.Context.Services.AddSingleton(sp =>
                                                      naosOptions.Context.Configuration?.GetSection(section).Get <ServiceDiscoveryConfiguration>());
            naosOptions.Context.Services.AddSingleton <IServiceRegistryClient>(sp =>
                                                                               new ServiceRegistryClient(sp.GetRequiredService <IServiceRegistry>()));

            optionsAction?.Invoke(new ServiceDiscoveryOptions(naosOptions.Context));

            //context.Messages.Add($"{LogEventKeys.General} naos services builder: service discovery added");

            return(naosOptions);
        }
예제 #17
0
        public static NaosServicesContextOptions AddJobScheduling(
            this NaosServicesContextOptions naosOptions,
            Action <JobSchedulerOptions> optionsAction = null,
            string section = "naos:scheduling")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // needed for mediator
            naosOptions.Context.Services.Scan(scan => scan
                                              .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                                              .AddClasses(classes => classes.Where(c => c.Name.EndsWith("JobEventHandler", StringComparison.OrdinalIgnoreCase)))
                                              //.FromAssembliesOf(typeof(JobEventHandler<>))
                                              //.AddClasses()
                                              .AsImplementedInterfaces());

            naosOptions.Context.Services.AddSingleton <IJobScheduler>(sp =>
            {
                var options = new JobSchedulerOptions(
                    sp.GetRequiredService <ILoggerFactory>(),
                    sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)) as IMediator,
                    new ServiceProviderJobFactory(sp.CreateScope().ServiceProvider));
                optionsAction?.Invoke(options);

                return(new JobScheduler(
                           sp.GetRequiredService <ILoggerFactory>(),
                           sp.CreateScope().ServiceProvider.GetService(typeof(ITracer)) as ITracer,
                           new InProcessMutex(sp.GetRequiredService <ILoggerFactory>()),
                           options));
            });

            naosOptions.Context.Services.AddSingleton <IHostedService>(sp =>
                                                                       new JobSchedulerHostedService(sp.GetRequiredService <ILoggerFactory>(), sp.GetRequiredService <IJobScheduler>()));

            naosOptions.Context.Messages.Add("naos services builder: job scheduling added"); // TODO: list available commands/handlers
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "JobScheduling", EchoRoute = "naos/jobscheduling/echo"
            });

            return(naosOptions);
        }
예제 #18
0
        /// <summary>
        /// Adds required services to support the command handling functionality.
        /// </summary>
        /// <param name="naosOptions"></param>
        /// <param name="optionsAction"></param>
        public static NaosServicesContextOptions AddCommands(
            this NaosServicesContextOptions naosOptions,
            Action <CommandsOptions> optionsAction = null)
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // needed for mediator, register command behaviors
            naosOptions.Context.Services
            .Scan(scan => scan     // https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
                  .FromExecutingAssembly()
                  .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                  .AddClasses(classes => classes.AssignableTo(typeof(ICommandBehavior)), true));

            // needed for mediator, register all commands + handlers
            naosOptions.Context.Services
            .Scan(scan => scan
                  .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" }))
                  .AddClasses(classes => classes.Where(c =>
                                                       (c.Name.EndsWith("Command", StringComparison.OrdinalIgnoreCase) || c.Name.EndsWith("CommandHandler", StringComparison.OrdinalIgnoreCase) ||
                                                        c.Name.EndsWith("Query", StringComparison.OrdinalIgnoreCase) || c.Name.EndsWith("QueryHandler", StringComparison.OrdinalIgnoreCase)) &&
                                                       !c.Name.Contains("ConsoleCommand")))
                  .AsImplementedInterfaces().WithScopedLifetime());

            naosOptions.Context.Messages.Add("naos services builder: commands added"); // TODO: list available commands/handlers

            optionsAction?.Invoke(new CommandsOptions(naosOptions.Context));
            //naosOptions.Context.Services
            //    .AddSingleton<ICommandBehavior, ValidateCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, TrackCommandBehavior>()
            //    //.AddSingleton<ICommandBehavior, ServiceContextEnrichCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, IdempotentCommandBehavior>()
            //    .AddSingleton<ICommandBehavior, PersistCommandBehavior>();

            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Commands", EchoRoute = "naos/commands/echo"
            });

            return(naosOptions);
        }
예제 #19
0
        public static NaosServicesContextOptions AddJobScheduling(
            this NaosServicesContextOptions naosOptions,
            Action <JobSchedulerOptions> optionsAction = null,
            string section = "naos:scheduling")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // needed for mediator
            naosOptions.Context.Services.Scan(scan => scan
                                              .FromApplicationDependencies()
                                              .AddClasses(classes => classes.Where(c => c.Name.EndsWith("JobEventHandler")))
                                              //.FromAssembliesOf(typeof(JobEventHandler<>))
                                              //.AddClasses()
                                              .AsImplementedInterfaces());

            naosOptions.Context.Services.AddSingleton <IJobScheduler>(sp =>
            {
                var settings = new JobSchedulerOptions(
                    sp.GetRequiredService <ILoggerFactory>(),
                    sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)) as IMediator,
                    new ServiceProviderJobFactory(sp));
                optionsAction?.Invoke(settings);

                return(new JobScheduler(
                           sp.GetRequiredService <ILoggerFactory>(),
                           new InProcessMutex(sp.GetRequiredService <ILoggerFactory>()),
                           settings));
            });

            naosOptions.Context.Services.AddSingleton <IHostedService>(sp =>
                                                                       new JobSchedulerHostedService(sp.GetRequiredService <ILoggerFactory>(), sp.GetRequiredService <IJobScheduler>()));

            naosOptions.Context.Messages.Add($"{LogEventKeys.Startup} naos services builder: job scheduling added"); // TODO: list available commands/handlers
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "JobScheduling", EchoRoute = "api/echo/jobscheduling"
            });

            return(naosOptions);
        }
예제 #20
0
        public static NaosServicesContextOptions AddModule <TModule>(
            this NaosServicesContextOptions naosOptions,
            string section = null)
            where TModule : class
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));
            EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context));

            // TODO: create T instance with Factory.Creat<T>() and call inst.AddModule(options) << see CompositionRoot examples
            var module = Factory <TModule> .Create();

            //if (section.IsNullOrEmpty())
            //{
            //    module.Configure(new ModuleOptions(naosOptions.Context));
            //}
            //else
            //{
            //    module.Configure(new ModuleOptions(naosOptions.Context), section);
            //}

            return(naosOptions);
        }
예제 #21
0
        public static NaosServicesContextOptions AddAuthenticationBasicStatic(
            this NaosServicesContextOptions naosOptions,
            Action <AuthenticationHandlerOptions> options = null,
            string section = "naos:authentication:basic:static")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));

            var serviceConfiguration = naosOptions.Context.Configuration.GetSection(section).Get <BasicStaticValidationServiceConfiguration>();

            naosOptions.Context.Services.AddSingleton <IAuthenticationService, BasicStaticValidationService>(sp => new BasicStaticValidationService(serviceConfiguration));

            naosOptions.Context.Services
            .AddAuthentication(AuthenticationKeys.BasicScheme)
            .AddBasic(options);

            naosOptions.Context.Messages.Add($"{LogEventKeys.Startup} naos services builder: authentication added (type=BasicStatic)");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Authentication", Description = "BasicStatic", EchoRoute = "api/echo/authentication"
            });

            return(naosOptions);
        }
예제 #22
0
        public static NaosServicesContextOptions AddApiKeyStaticAuthentication(
            this NaosServicesContextOptions naosOptions,
            Action <AuthenticationHandlerOptions> options = null,
            string section = "naos:authentication:apikey:static")
        {
            EnsureArg.IsNotNull(naosOptions, nameof(naosOptions));

            var serviceConfiguration = naosOptions.Context.Configuration.GetSection(section).Get <ApiKeyStaticValidationServiceConfiguration>();

            naosOptions.Context.Services.AddSingleton <IAuthenticationService, ApiKeyStaticValidationService>(sp => new ApiKeyStaticValidationService(serviceConfiguration));

            naosOptions.Context.Services
            .AddAuthentication(AuthenticationKeys.ApiKeyScheme)
            .AddApiKey(options);

            naosOptions.Context.Messages.Add($"naos services builder: authentication added (type={AuthenticationKeys.ApiKeyScheme})");
            naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation {
                Name = "Authentication", Description = "ApiKeyStatic", EchoRoute = "naos/authentication/echo"
            });

            return(naosOptions);
        }