コード例 #1
0
 /// <summary>
 /// This API supports the Entity Framework Core infrastructure and is not intended to be used
 /// directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public MongoDbOptionsExtension([CanBeNull] MongoDbOptionsExtension existing = null)
 {
     if (existing != null)
     {
         _mongoClient  = existing.MongoClient;
         _databaseName = existing.DatabaseName;
     }
 }
コード例 #2
0
        /// <summary>
        /// Sets the name of the MongoDB database to use with the <see cref="DbContext"/> being configured.
        /// </summary>
        /// <param name="databaseName">The name of the MongoDB database instance to use with the current <see cref="DbContext"/>.</param>
        /// <returns>This <see cref="MongoDbOptionsExtension"/>, so that calls can be chained.</returns>
        public MongoDbContextOptionsBuilder UseDatabase([NotNull] string databaseName)
        {
            Check.NotEmpty(databaseName, nameof(databaseName));
            MongoDbOptionsExtension extension = CloneExtension();

            extension.DatabaseName = databaseName;
            ((IDbContextOptionsBuilderInfrastructure)OptionsBuilder).AddOrUpdateExtension(extension);
            return(this);
        }
コード例 #3
0
        private static DbContextOptionsBuilder SetupMongoDb(
            [NotNull] DbContextOptionsBuilder optionsBuilder,
            [NotNull] Action <MongoDbOptionsExtension> mongoDbOptionsExtensionAction,
            [CanBeNull] Action <MongoDbContextOptionsBuilder> mongoDbOptionsAction)
        {
            MongoDbOptionsExtension extension = GetOrCreateExtension(optionsBuilder);

            mongoDbOptionsExtensionAction(extension);
            ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);

            ConfigureWarnings(optionsBuilder);

            mongoDbOptionsAction?.Invoke(new MongoDbContextOptionsBuilder(optionsBuilder));

            return(optionsBuilder);
        }
コード例 #4
0
        /// <summary>
        /// Registers default implementations of all services not already registered by the provider. Database providers must call
        /// this method as the last step of service registration--that is, after all provider services have been registered.
        /// </summary>
        /// <returns>This builder, such that further calls can be chained.</returns>
        public override EntityFrameworkServicesBuilder TryAddCoreServices()
        {
            TryAdd <IDatabaseProvider, DatabaseProvider <MongoDbOptionsExtension> >();
            TryAdd <IModelValidator, MongoDbModelValidator>();
            TryAdd <ITypeMappingSource>(serviceProvider => serviceProvider.GetRequiredService <IMongoDbTypeMappingSource>());
            TryAdd <IMongoDbTypeMappingSource, MongoDbTypeMappingSource>();
            TryAdd <IDatabase, MongoDbDatabase>();
            TryAdd <IDatabaseCreator, MongoDbDatabaseCreator>();
            TryAdd <IValueGeneratorSelector, MongoDbValueGeneratorSelector>();
            TryAdd <IConventionSetBuilder, MongoDbConventionSetBuilder>();
            TryAdd <IQueryContextFactory, MongoDbQueryContextFactory>();
            TryAdd <IEntityQueryableExpressionVisitorFactory, MongoDbEntityQueryableExpressionVisitorFactory>();
            TryAdd <IEntityQueryModelVisitorFactory, MongoDbEntityQueryModelVisitorFactory>();
            TryAdd <IMemberAccessBindingExpressionVisitorFactory, MongoDbMemberAccessBindingExpressionVisitorFactory>();
            TryAdd <INavigationRewritingExpressionVisitorFactory, DocumentNavigationRewritingExpressionVisitorFactory>();

            TryAddProviderSpecificServices(serviceCollectionMap =>
            {
                serviceCollectionMap.TryAddScoped(serviceProvider =>
                {
                    MongoDbOptionsExtension extension = serviceProvider
                                                        .GetRequiredService <IDbContextOptions>()
                                                        .FindExtension <MongoDbOptionsExtension>();
                    return(extension?.MongoClient ?? new MongoClient());
                });
                serviceCollectionMap.TryAddScoped <IMongoDbConnection, MongoDbConnection>();
                serviceCollectionMap.TryAddScoped <IMongoDbDenormalizedCollectionCompensatingVisitorFactory, MongoDbDenormalizedCollectionCompensatingVisitorFactory>();
                serviceCollectionMap.TryAddScoped <IDocumentQueryExpressionFactory, MongoDbDocumentQueryExpressionFactory>();
                serviceCollectionMap.TryAddScoped <IMongoDbWriteModelFactoryCache, MongoDbWriteModelFactoryCache>();
                serviceCollectionMap.TryAddScoped <IMongoDbWriteModelFactorySelector, MongoDbWriteModelFactorySelector>();
                serviceCollectionMap.TryAddScoped <IEntityLoadInfoFactory, EntityLoadInfoFactory>();
                serviceCollectionMap.TryAddScoped <IValueBufferFactory, ValueBufferFactory>();
            });

            ServiceCollectionMap.GetInfrastructure()
            .AddDependencyScoped <MongoDbConventionSetBuilderDependencies>()
            .AddDependencyScoped <MongoDbEntityQueryModelVisitorDependencies>();

            return(base.TryAddCoreServices());
        }