Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public static void AddInfraDataConfiguration(this IServiceCollection services,
                                                     IConfiguration configuration)
        {
            //Context
            IDictionary <string, string> configSectionNoSql = configuration.GetSection("MongoSettings").GetChildren().ToDictionary(x => x.Key, x => x.Value);

            configSectionNoSql.TryGetValue("Connection", out string conex);
            configSectionNoSql.TryGetValue("DatabaseName", out string database);
            configSectionNoSql.TryGetValue("FlagTls", out string flagTls);
            configSectionNoSql.TryGetValue("FlagAllowInsecureTls", out string flagAllowInsecureTls);

            var noSqlSettings = new NoSqlSettings(conex, database);

            noSqlSettings.flagTls = flagTls != "" ? flagTls.Equals("S") : noSqlSettings.flagTls;
            noSqlSettings.flagAllowInsecureTls = flagAllowInsecureTls != "" ? flagAllowInsecureTls.Equals("S") : noSqlSettings.flagAllowInsecureTls;

            services.AddScoped <INoSqlContext>(x => new NoSqlContext(_noSqlSettings: noSqlSettings));

            ConfigureClassMaps();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct method
        /// </summary>
        protected NoSqlContextBase(NoSqlSettings _noSqlSettings)
        {
            noSqlSettings = _noSqlSettings;

            /*
             * // Configure mongo (You can inject the config, just to simplify)
             * IDictionary<string, string> configSectionNoSql = this.Configuration.GetSection(noSqlSettings.keySettings).GetChildren().ToDictionary(x => x.Key, x => x.Value);
             * configSectionNoSql.TryGetValue(noSqlSettings.keyConnection, out string conex);
             * configSectionNoSql.TryGetValue(noSqlSettings.keyDbName, out string database);
             */

            RetryPolicy retryPolicy = Policy.Handle <DnsResponseException>()
                                      .WaitAndRetry(new[] {
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(6),
                TimeSpan.FromSeconds(9)
            });

            MongoClientSettings clientSettings = MongoClientSettings.FromConnectionString(noSqlSettings.connection);

            clientSettings.UseTls           = noSqlSettings.flagTls;
            clientSettings.AllowInsecureTls = noSqlSettings.flagAllowInsecureTls;

            retryPolicy.Execute(() => {
                noSqlClient = new MongoClient(clientSettings);
                database    = noSqlClient.GetDatabase(noSqlSettings.database, new MongoDatabaseSettings());
            });

            // Set Guid to CSharp style (with dash -)
            BsonDefaults.GuidRepresentation = GuidRepresentation.CSharpLegacy;

            // Every command will be stored and it'll be processed at SaveChanges
            listCommands = new List <Func <Task> >();

            registerConventions();
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 public NoSqlContext(NoSqlSettings _noSqlSettings) : base(_noSqlSettings)
 {
 }