Esempio n. 1
0
        public static IServiceCollection AddMongoDbContext <TContext>(this IServiceCollection serviceCollection, Action <MongoDbContextOptionsBuilder> optionsAction) where TContext : MongoContext
        {
            var options = new MongoDbContextOptionsBuilder();

            optionsAction(options);
            serviceCollection.AddSingleton <MongoDbContextOptions>(options.Options);
            serviceCollection.AddSingleton <MongoContext, MongoDbContext>();
            return(serviceCollection);
        }
        private static MongoDbContextOptions <TDbContext> CreateDbContextOptions <TDbContext>(
            [NotNull] IServiceProvider applicationServiceProvider,
            [CanBeNull] Action <MongoDbContextOptionsBuilder <TDbContext> > optionsAction) where TDbContext : MongoDbContext
        {
            MongoDbContextOptionsBuilder <TDbContext> builder = new MongoDbContextOptionsBuilder <TDbContext>();

            builder.UseApplicationServiceProvider(applicationServiceProvider);

            optionsAction?.Invoke(builder);

            return(builder.Options);
        }