public static IServiceCollection AddInfra(this IServiceCollection services, Action <InfraOptions> optionAction)
        {
            services.NotNull(nameof(services));
            services.NotNull(nameof(optionAction));

            services.Configure(optionAction);

            services.TryAddEnumerable(ServiceDescriptor.Scoped <IConfigureOptions <IdentityServiceOptions>, DbConfiguredOption>());

            services.AddCap(options =>
            {
                var source = new InfraOptions();
                optionAction(source);

                options.UseRabbitMQ(source.RabbitMQHost);

                options.UsePostgreSql(source.ConnectionString);
            });

            services.AddDbContext <IdentityServiceContext>((sp, options) =>
            {
                var source = sp.GetRequiredService <IOptions <InfraOptions> >().Value;
                options.UseNpgsql(source.ConnectionString, npgsql =>
                {
                    npgsql.MigrationsAssembly(Assembly.GetEntryAssembly().GetName().Name);
                });
            });

            return(services);
        }
Exemplo n.º 2
0
 public DbConfiguredOption(IOptions <InfraOptions> options)
 {
     _options = options.NotNull(nameof(options)).Value;
 }