Exemplo n.º 1
0
        public static IServiceCollection AddServiceClient <TClient>(this INaosBuilderContext context, Action <IHttpClientBuilder> setupAction = null)
            where TClient : ServiceDiscoveryClient
        {
            EnsureArg.IsNotNull(context, nameof(context));

            context.Messages.Add($"naos services builder: typed service client added (type={typeof(TClient).Name})");

            if (setupAction != null)
            {
                var builder = context.Services.AddHttpClient <TClient>();
                setupAction.Invoke(builder);
            }
            else
            {
                // default setup
                context.Services
                .AddHttpClient <TClient>()
                .AddNaosMessageHandlers()
                .AddNaosPolicyHandlers();
            }

            context.Services.AddHealthChecks().AddServiceClient <TClient>();

            return(context.Services);
        }
Exemplo n.º 2
0
 public LoggingOptions(
     INaosBuilderContext context,
     LoggerConfiguration loggerConfiguration)
 {
     this.Context             = context;
     this.LoggerConfiguration = loggerConfiguration;
 }
Exemplo n.º 3
0
        public static INaosBuilderContext AddAzureLogAnalyticsTracing(this INaosBuilderContext context, string logName)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(context.Services, nameof(context.Services));

            var configuration = context.Configuration?.GetSection("naos:operations:tracing:azureLogAnalytics").Get <LogAnalyticsConfiguration>(); // TODO: move to operations:tracing:azureLogAnalytics

            if (configuration != null)
            {
                context.Services.AddScoped <ILogTraceRepository>(sp =>
                {
                    // authenticate api https://dev.int.loganalytics.io/documentation/1-Tutorials/ARM-API
                    var token = new AuthenticationContext(
                        $"https://login.microsoftonline.com/{configuration.ApiAuthentication?.TenantId}", false)
                                .AcquireTokenAsync(
                        configuration.ApiAuthentication?.Resource ?? "https://management.azure.com",
                        new ClientCredential(
                            configuration.ApiAuthentication?.ClientId,
                            configuration.ApiAuthentication?.ClientSecret)).Result;

                    configuration.LogName ??= $"{logName.Replace("_CL", string.Empty)}_CL";
                    return(new LogAnalyticsLogTraceRepository(
                               sp.GetRequiredService <ILoggerFactory>(),
                               new System.Net.Http.HttpClient(), // TODO: resolve from container!
                               configuration,
                               token?.AccessToken));
                });
                context.Messages.Add($"naos services builder: logging azure loganalytics repository added (name={logName}_CL, workspace={configuration.WorkspaceId})");
            }

            return(context);
        }
Exemplo n.º 4
0
        public static INaosBuilderContext AddMongoLogging(this INaosBuilderContext context)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNull(context.Services, nameof(context.Services));

            var configuration = context.Configuration?.GetSection("naos:operations:logging:mongo").Get <MongoLoggingConfiguration>();

            if (configuration != null)
            {
                context.Services.AddMongoClient("logging", new MongoConfiguration
                {
                    ConnectionString = configuration.ConnectionString?.Replace("[DATABASENAME]", configuration.DatabaseName),
                    DatabaseName     = configuration.DatabaseName
                });

                context.Services.AddScoped <ILogEventRepository>(sp =>
                {
                    return(new MongoLogEventRepository(o => o
                                                       .LoggerFactory(sp.GetRequiredService <ILoggerFactory>())
                                                       .MongoClient(sp.GetServices <IMongoClient>()
                                                                    .FirstOrDefault(c => c.Settings.ApplicationName == "logging")) //TODO: make nice extension to get a named mongoclient
                                                       .Mapper(new AutoMapperEntityMapper(MapperFactory.Create()))
                                                       .DatabaseName(configuration.DatabaseName)
                                                       .CollectionName(configuration.CollectionName)));
                });
                context.Messages.Add($"naos services builder: logging azure mongo repository added (collection={configuration.CollectionName})");
            }

            return(context);
        }
Exemplo n.º 5
0
        public static IServiceCollection AddServiceClient(this INaosBuilderContext context, string name, Action <IHttpClientBuilder> setupAction = null)
        {
            EnsureArg.IsNotNull(context, nameof(context));
            EnsureArg.IsNotNullOrEmpty(name, nameof(name));

            context.Messages.Add($"naos services builder: named service client added (name={name})");

            if (setupAction != null)
            {
                var builder = context.Services.AddHttpClient(name);
                setupAction.Invoke(builder);
            }
            else
            {
                // default setup
                context.Services
                .AddHttpClient(name)
                .AddNaosMessageHandlers()
                .AddNaosPolicyHandlers();
            }

            return(context.Services);
        }
Exemplo n.º 6
0
 public ModuleOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 7
0
 public CommandRequestOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 8
0
 public OperationsTracingOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 9
0
 public MessagingOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 10
0
 public ServiceDiscoveryRouterOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 11
0
 public QueueingProviderOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 12
0
 public RequestStorageOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 13
0
 public NaosServicesContextOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }
Exemplo n.º 14
0
 public JobSchedulingOptions(INaosBuilderContext context)
 {
     this.Context = context;
 }