public static BodyGenesisAppBuilder UseMongoDB(this BodyGenesisAppBuilder builder, Action <MongoDBOptions> configure = null) { configure = configure ?? new Action <MongoDBOptions>(o => { }); builder .AddOptions <MongoDBOptions>() .Bind(builder.Configuration.GetSection("BodyGenesis:Infrastructure:MongoDB")) .Configure(configure); builder .AddSingleton <IMongoClient>(provider => { var mongoDbOptions = provider.GetRequiredService <IOptions <MongoDBOptions> >(); return(new MongoClient(mongoDbOptions.Value.ConnectionString)); }) .AddSingleton(provider => { var mongoDbOptions = provider.GetRequiredService <IOptions <MongoDBOptions> >(); var mongoClient = provider.GetRequiredService <IMongoClient>(); return(mongoClient.GetDatabase(mongoDbOptions.Value.DatabaseName)); }) .AddTransient(typeof(IRepository <>), typeof(MongoDBRepository <>)); BsonSerializer.RegisterSerializer(typeof(DateTime), new DateTimeSerializer(DateTimeKind.Local)); return(builder); }
public static IServiceCollection AddBodyGenesis(this IServiceCollection services, IConfiguration configuration, Action <BodyGenesisAppBuilder> buildApp) { var builder = new BodyGenesisAppBuilder(services, configuration); buildApp(builder); return(services); }
public static BodyGenesisAppBuilder UseSendGrid(this BodyGenesisAppBuilder builder, Action <SendGridOptions> configure = null) { configure = configure ?? new Action <SendGridOptions>(o => { }); builder.AddOptions <SendGridOptions>() .Bind(builder.Configuration.GetSection("BodyGenesis:Infrastructure:SendGrid")) .Configure(configure); builder .AddTransient <ISendGridClient>(provider => { var options = provider.GetRequiredService <IOptions <SendGridOptions> >(); return(new SendGridClient(options.Value.ApiKey)); }) .AddTransient <IEmailSender, SendGridEmailSender>(); return(builder); }