Exemple #1
0
 /// <summary>
 /// Initialize
 /// </summary>
 /// <param name="connectionUrl">Connection url</param>
 /// <param name="mappings">Dapper entity mappings</param>
 public MongoDBDatabaseContext(
     MongoUrl connectionUrl,
     MongoDBEntityMappings mappings)
 {
     Mappings = mappings;
     Database = new MongoClient(connectionUrl).GetDatabase(connectionUrl.DatabaseName);
 }
Exemple #2
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 /// <param name="connectionUrl">Connection url</param>
 /// <param name="mappings">Dapper entity mappings</param>
 public MongoDBDatabaseContext(
     MongoUrl connectionUrl,
     MongoDBEntityMappings mappings)
 {
     Mappings      = mappings;
     MongoDatabase = new MongoClient(connectionUrl).GetDatabase(connectionUrl.DatabaseName);
     CommandLogger = Application.Ioc.Resolve <IDatabaseCommandLogger>(IfUnresolved.ReturnDefault);
 }
Exemple #3
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 /// <param name="database">Database type</param>
 /// <param name="connectionString">Connection string</param>
 public MongoDBDatabaseContextFactory(string database, string connectionString)
 {
     if (string.Compare(database, "MongoDB", true) != 0)
     {
         throw new ArgumentException($"Database type should be MongoDB");
     }
     ConnectionUrl = new MongoUrl(connectionString);
     if (string.IsNullOrEmpty(ConnectionUrl.DatabaseName))
     {
         throw new ArgumentException("Please set the database name in connection string");
     }
     Mappings = new MongoDBEntityMappings(ConnectionUrl);
 }
        /// <summary>
        /// Initialize<br/>
        /// 初始化<br/>
        /// </summary>
        /// <param name="connectionUrl">Connection url</param>
        /// <param name="mappings">Dapper entity mappings</param>
        public MongoDBDatabaseContext(
            MongoUrl connectionUrl,
            MongoDBEntityMappings mappings)
        {
            Mappings = mappings;
            var mongoClientSettings = MongoClientSettings.FromUrl(connectionUrl);

            mongoClientSettings.ClusterConfigurator = cb => {
                cb.Subscribe <CommandStartedEvent>(e => {
                    CommandLogger?.LogCommand(this, $"{e.CommandName}: {e.Command.ToJson()}", e.Command);
                });
            };
            MongoDatabase = new MongoClient(mongoClientSettings).GetDatabase(connectionUrl.DatabaseName);
            CommandLogger = Application.Ioc.Resolve <IDatabaseCommandLogger>(IfUnresolved.ReturnDefault);
        }
Exemple #5
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 public MongoDBDatabaseContextFactory(
     string database, string connectionString,
     IEnumerable <IDatabaseInitializeHandler> handlers,
     IEnumerable <IEntityMappingProvider> providers)
 {
     if (string.Compare(database, "MongoDB", true, CultureInfo.InvariantCulture) != 0)
     {
         throw new ArgumentException($"Database type should be MongoDB");
     }
     ConnectionUrl = new MongoUrl(connectionString);
     if (string.IsNullOrEmpty(ConnectionUrl.DatabaseName))
     {
         throw new ArgumentException("Please set the database name in connection string");
     }
     Mappings = new MongoDBEntityMappings(ConnectionUrl, handlers, providers);
 }