public static ServiceOptions AddSampleCountries( this ServiceOptions options) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.AddTag("Countries"); options.Context.Services.AddScoped <ICountryRepository>(sp => { return(new CountryRepository( new RepositoryLoggingDecorator <Country>( sp.GetRequiredService <ILogger <CountryRepository> >(), new RepositoryTenantDecorator <Country>( "naos_sample_test", new RepositoryOrderDecorator <Country>( e => e.Name, new InMemoryRepository <Country, DbCountry>( sp.GetRequiredService <ILogger <IRepository <Country> > >(), sp.GetRequiredService <IMediator>(), e => e.Identifier, sp.GetRequiredService <InMemoryContext <Country> >(), // singleton new RepositoryOptions( new AutoMapperEntityMapper(ModelMapperConfiguration.Create())), new[] { new AutoMapperSpecificationMapper <Country, DbCountry>(ModelMapperConfiguration.Create()) })))))); }); options.Context.Services.AddSingleton(sp => new InMemoryContext <Country>(new[] { new Country { Code = "de", LanguageCodes = new[] { "de-de" }, Name = "Germany", TenantId = "naos_sample_test", Id = "de" }, new Country { Code = "nl", LanguageCodes = new[] { "nl-nl" }, Name = "Netherlands", TenantId = "naos_sample_test", Id = "nl" }, new Country { Code = "be", LanguageCodes = new[] { "fr-be", "nl-be" }, Name = "Belgium", TenantId = "naos_sample_test", Id = "be" }, }.ToList())); options.Context.Messages.Add($"{LogKeys.Startup} naos services builder: countries service added"); return(options); }
public static ServiceOptions AddSampleUserAccounts( this ServiceOptions options, string section = "naos:sample:userAccounts:entityFramework", UserAccountsContext dbContext = null) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.AddTag("UserAccounts"); if (dbContext != null) { options.Context.Services.AddSingleton(dbContext); // cross wiring, warning this will be a singleton (not scoped) } options.Context.Services.AddScoped <IRepository <UserAccount> >(sp => { return(new UserAccountRepository( new RepositoryLoggingDecorator <UserAccount>( sp.GetRequiredService <ILogger <UserAccountRepository> >(), new RepositoryTenantDecorator <UserAccount>( "naos_sample_test", // TODO: resolve from runtime context new EntityFrameworkRepository <UserAccount>(o => o .LoggerFactory(sp.GetRequiredService <ILoggerFactory>()) .Mediator(sp.GetRequiredService <IMediator>()) .DbContext(sp.GetRequiredService <UserAccountsContext>())))))); }); var entityFrameworkConfiguration = options.Context.Configuration?.GetSection(section).Get <EntityFrameworkConfiguration>(); options.Context.Services.AddDbContext <UserAccountsContext>(o => { o.UseLoggerFactory(options.Context.Services.BuildServiceProvider().GetRequiredService <ILoggerFactory>()); o.UseNaosSqlServer(entityFrameworkConfiguration.ConnectionString); o.UseQueryTrackingBehavior(EntityFrameworkCore.QueryTrackingBehavior.NoTracking); }); options.Context.Services.AddHealthChecks() .AddSqlServer(entityFrameworkConfiguration.ConnectionString, name: "UserAccounts-sqlserver"); options.Context.Messages.Add($"{LogKeys.Startup} naos services builder: useraccounts service added"); return(options); }
public static ServiceOptions AddSampleCustomers( this ServiceOptions options, string section = "naos:sample:customers") { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNull(options.Context, nameof(options.Context)); options.Context.AddTag("Customers"); options.Context.AddServiceClient <UserAccountsClient>(); var cosmosDbConfiguration = options.Context.Configuration?.GetSection($"{section}:cosmosDb").Get <CosmosDbConfiguration>(); options.Context.Services.AddScoped <ICustomerRepository>(sp => { return(new CustomerRepository( new RepositoryLoggingDecorator <Customer>( sp.GetRequiredService <ILogger <CustomerRepository> >(), new RepositoryTenantDecorator <Customer>( "naos_sample_test", new CosmosDbSqlRepository <Customer>(o => o .LoggerFactory(sp.GetRequiredService <ILoggerFactory>()) .Mediator(sp.GetRequiredService <IMediator>()) .Provider(new CosmosDbSqlProviderV2 <Customer>( logger: sp.GetRequiredService <ILogger <CosmosDbSqlProviderV2 <Customer> > >(), client: CosmosDbClientV2.Create(cosmosDbConfiguration.ServiceEndpointUri, cosmosDbConfiguration.AuthKeyOrResourceToken), databaseId: cosmosDbConfiguration.DatabaseId, collectionIdFactory: () => cosmosDbConfiguration.CollectionId, partitionKeyPath: cosmosDbConfiguration.CollectionPartitionKey, throughput: cosmosDbConfiguration.CollectionOfferThroughput, isMasterCollection: cosmosDbConfiguration.IsMasterCollection))))))); }); options.Context.Services.AddScoped <ICosmosDbSqlProvider <Customer> >(sp => { return(new CosmosDbSqlProviderV3 <Customer>(o => o .LoggerFactory(sp.GetRequiredService <ILoggerFactory>()) .Account(cosmosDbConfiguration.ServiceEndpointUri, cosmosDbConfiguration.AuthKeyOrResourceToken) .Database(cosmosDbConfiguration.DatabaseId))); }); var queueStorageConfiguration = options.Context.Configuration?.GetSection($"{section}:queueStorage").Get <QueueStorageConfiguration>(); options.Context.Services.AddSingleton <IQueue>(sp => { var q1 = new AzureStorageQueue <Customer>( new AzureStorageQueueOptionsBuilder() .LoggerFactory(sp.GetRequiredService <ILoggerFactory>()) .ConnectionString(queueStorageConfiguration.ConnectionString).Build()); _ = q1.EnqueueAsync(new Customer()).Result; _ = q1.EnqueueAsync(new Customer()).Result; return(q1); }); options.Context.Services .AddHealthChecks() .AddAzureQueueStorage( queueStorageConfiguration.ConnectionString, name: "Customers-queueStorage"); //options.Context.Services.AddSingleton<IValidator<CreateCustomerCommand>>(new CreateCustomerCommandValidator()); options.Context.Services .AddHealthChecks() .AddDocumentDb(s => { s.UriEndpoint = cosmosDbConfiguration.ServiceEndpointUri; s.PrimaryKey = cosmosDbConfiguration.AuthKeyOrResourceToken; }, name: "Customers-cosmosdb") .AddServiceDiscoveryClient <UserAccountsClient>(); options.Context.Messages.Add($"{LogKeys.Startup} naos services builder: customers service added"); return(options); }
private static IServiceCollection AddGrpcClients(this IServiceCollection services, ServiceOptions serviceOptions) { services.AddGrpcClientOptions <Email.EmailClient>(serviceOptions.Notification.Grpc); return(services); }