Exemple #1
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .ConfigureAppConfiguration((context, config) =>
                            NaosConfigurationFactory.Extend(config, args, context.HostingEnvironment.EnvironmentName))
 //.UseUrls($"https://localhost:{GetNextAvailablePort()}")
 .UseStartup <Startup>()
 .UseSerilog();
Exemple #2
0
        protected BaseTest()
        {
            Environment.SetEnvironmentVariable(EnvironmentKeys.Environment, "Development");
            Environment.SetEnvironmentVariable(EnvironmentKeys.IsLocal, "True");

            var configuration = NaosConfigurationFactory.Create();

            // naos core registrations
            this.services
            .AddMediatR()
            .AddNaos(configuration, "Product", "Capability", new[] { "All" }, n => n
                     .AddServices(o => o
                                  .AddSampleCountries()
                                  .AddSampleCustomers()
                                  .AddSampleUserAccounts(
                                      dbContext: new UserAccountsContext(new DbContextOptionsBuilder().UseNaosSqlServer(configuration, "naos:sample:userAccounts:entityFramework").Options)))
                     .AddOperations(o => o
                                    .AddLogging(correlationId: $"TEST{IdGenerator.Instance.Next}"))
                     .AddMessaging(o => o
                                   //.AddFileSystemBroker()
                                   //.AddSignalRBroker()
                                   .UseServiceBusBroker())
                     .AddCommands());

            this.services.AddSingleton <ICommandBehavior, ValidateCommandBehavior>(); // new ValidateCommandBehavior(false)
            this.services.AddSingleton <ICommandBehavior, TrackCommandBehavior>();
            this.services.AddSingleton <ICommandBehavior>(new FileStoragePersistCommandBehavior(
                                                              new FolderFileStorage(o => o
                                                                                    .Folder(Path.Combine(Path.GetTempPath(), "naos_filestorage", "commands")))));
            //this.services.AddSingleton<ICommandBehavior, ServiceContextEnrichCommandBehavior>();
            //this.services.AddSingleton<ICommandBehavior, IdempotentCommandBehavior>();
            //this.services.AddSingleton<ICommandBehavior, PersistCommandBehavior>();

            this.ServiceProvider = this.services.BuildServiceProvider();
        }
Exemple #3
0
        /// <summary>
        /// Adds required services to support the Discovery functionality.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="product"></param>
        /// <param name="capability"></param>
        /// <param name="tags"></param>
        /// <param name="optionsAction"></param>
        /// <param name="environment"></param>
        /// <param name="section"></param>
        public static INaosBuilderContext AddNaos(
            this IServiceCollection services,
            string product    = null,
            string capability = null,
            string[] tags     = null,
            Action <NaosServicesContextOptions> optionsAction = null,
            string environment = null,
            string section     = "naos")
        {
            Console.WriteLine("--- naos service start", System.Drawing.Color.LimeGreen);
            EnsureArg.IsNotNull(services, nameof(services));

            //using var serviceProvider = services.BuildServiceProvider();
            var configuration = /*serviceProvider.GetService<IConfiguration>() ??*/ NaosConfigurationFactory.Create();

            services.AddSingleton(configuration);
            services.AddMediatr();
            services.Configure <ConsoleLifetimeOptions>(opts => opts.SuppressStatusMessages = true); // https://andrewlock.net/new-in-aspnetcore-3-structured-logging-for-startup-messages/

            var naosConfiguration = configuration?.GetSection(section).Get <NaosConfiguration>();
            var context           = new NaosBuilderContext
            {
                Services      = services,
                Configuration = configuration,
                Environment   = environment ?? Environment.GetEnvironmentVariable(EnvironmentKeys.Environment) ?? "Production",
                Descriptor    = new Naos.Foundation.ServiceDescriptor(
                    product ?? naosConfiguration.Product,
                    capability ?? naosConfiguration.Product,
                    tags: tags ?? naosConfiguration.Tags),
            };

            foreach (var provider in configuration?.Providers.Safe())
            {
                context.Messages.Add($"naos services builder: configuration provider added (type={provider.GetType().Name})");
            }

            context.Messages.Add("naos services builder: naos services added");
            //context.Services.AddSingleton(new NaosFeatureInformation { Name = "Naos", EchoRoute = "naos/servicecontext/echo" });

            // TODO: optional or provide own settings?
            JsonConvert.DefaultSettings = DefaultJsonSerializerSettings.Create;

            optionsAction?.Invoke(new NaosServicesContextOptions(context));

            AddConfigurationHealthChecks(services, configuration);
            LogStartupMessages(services, context);

            return(context);
        }
Exemple #4
0
        public JobSchedulerTests()
        {
            var configuration = NaosConfigurationFactory.Create();

            this.services
            .AddNaos(configuration, "Product", "Capability", new[] { "All" }, n => n
                     .AddOperations(o => o
                                    .AddLogging(correlationId: $"TEST{IdGenerator.Instance.Next}"))
                     .AddJobScheduling());

            this.services.AddScoped <StubProbe>();

            this.ServiceProvider = this.services.BuildServiceProvider();
            this.sut             = this.ServiceProvider.GetRequiredService <IJobScheduler>();
        }
        public LogEventRepositoryTests()
        {
            var configuration = NaosConfigurationFactory.Create();

            this.services
            .AddNaos(configuration, "Product", "Capability", new[] { "All" }, n => n
                     .AddOperations(o => o
                                    .AddLogging(
                                        l => l.UseAzureLogAnalytics(), // registers ILogEventRepository
                                        correlationId: $"TEST{RandomGenerator.GenerateString(9, true)}"))
                     .AddJobScheduling());

            this.ServiceProvider = this.services.BuildServiceProvider();
            this.sut             = this.ServiceProvider.GetService <ILogEventRepository>();
        }
Exemple #6
0
        public MessageBrokerTests()
        {
            var configuration = NaosConfigurationFactory.Create();

            this.services
            .AddMediatR()
            .AddNaos(configuration, "Product", "Capability", new[] { "All" }, n => n
                     .AddOperations(o => o
                                    .AddLogging(correlationId: $"TEST{RandomGenerator.GenerateString(9)}"))
                     .AddMessaging(o => o
                                   //.AddFileSystemBroker()
                                   //.AddSignalRBroker()
                                   .UseServiceBusBroker()));

            this.ServiceProvider = this.services.BuildServiceProvider();
            this.sut             = this.ServiceProvider.GetService <IMessageBroker>();
        }
Exemple #7
0
        public MessageBrokerTests()
        {
            var configuration = NaosConfigurationFactory.Create();

            this.Services
            .AddMediatR(AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.GetName().Name.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase)).ToArray())
            .AddNaos("Product", "Capability", new[] { "All" }, n => n
                     .AddOperations(o => o
                                    .AddLogging(correlationId: $"TEST{RandomGenerator.GenerateString(9)}"))
                     .AddMessaging(o => o
                                   //.AddFileSystemBroker()
                                   //.AddSignalRBroker()
                                   .UseServiceBusBroker()));

            this.ServiceProvider = this.Services.BuildServiceProvider();
            this.sut             = this.ServiceProvider.GetService <IMessageBroker>();
        }
Exemple #8
0
        public HttpClientTests()
        {
            var configuration = NaosConfigurationFactory.Create();

            this.services.AddTransient <HttpClientCorrelationHandler>();
            this.services.AddTransient <HttpClientLogHandler>();

            this.services
            .AddHttpClient("default")
            .AddHttpMessageHandler <HttpClientCorrelationHandler>();
            //.AddHttpMessageHandler<HttpClientLogHandler>();
            this.services.Replace(Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton <IHttpMessageHandlerBuilderFilter, HttpClientLogHandlerBuilderFilter>());

            this.services
            .AddNaos(configuration, "Product", "Capability", new[] { "All" }, n => n
                     .AddRequestCorrelation()
                     .AddOperations(o => o
                                    .AddLogging(correlationId: $"TEST{IdGenerator.Instance.Next}")));

            this.ServiceProvider = this.services.BuildServiceProvider();
        }
 public static IConfigurationBuilder AddNaos(this IConfigurationBuilder source, HostBuilderContext context)
 {
     NaosConfigurationFactory.Create(context, source);
     return(source);
 }
Exemple #10
0
 public Startup(ILogger <Startup> logger)
 {
     this.Configuration = NaosConfigurationFactory.Create();
     this.logger        = logger;
 }