Exemplo n.º 1
0
 public SagaStore(ISqlServerConnection con, IDateTimeProvider dateTimeProvider, SqlServerOptions sqlServerOptions)
 {
     _con = con;
     _dateTimeProvider   = dateTimeProvider;
     _sqlServerOptions   = sqlServerOptions;
     _serializerSettings = new JsonSerializerSettings()
     {
         ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
         TypeNameHandling      = TypeNameHandling.All,
         DateFormatHandling    = DateFormatHandling.IsoDateFormat
     };
 }
Exemplo n.º 2
0
        public static void AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddTransient <IDbSeed, DbSeed>();
            services.AddTransient <ICurrentUser, CurrentUser>();

            services.AddDbContext <IDbContext, TodoDbContext>(options =>
            {
                var sqlServerOptions = new SqlServerOptions();
                configuration.Bind("SqlServer", sqlServerOptions);
                options.UseSqlServer(sqlServerOptions.ConnectionString);
            });
        }
Exemplo n.º 3
0
        protected DatabaseTestHost()
        {
            Logger          = new Mock <ILogger <SqlServerStorage> >().Object;
            CapOptions      = new Mock <CapOptions>().Object;
            SqlSeverOptions = new SqlServerOptions()
            {
                ConnectionString = ConnectionUtil.GetConnectionString()
            };

            DiagnosticProcessorObserver = new DiagnosticProcessorObserver(new Mock <IDispatcher>().Object);

            InitializeDatabase();
        }
Exemplo n.º 4
0
        public static void UseSqlServer(this ITheSagaConfig config, SqlServerOptions options)
        {
            if (string.IsNullOrEmpty(options?.ConnectionString))
            {
                throw new Exception($"ConnectionString for TheSaga.Persistance.SqlServer cannot be empty");
            }

            config.Services.AddSingleton <SqlServerOptions>(ctx => options);
            config.Services.AddTransient <ISagaPersistance, SqlServerSagaPersistance>();
            config.Services.AddTransient <ISqlServerConnection>(ctx =>
            {
                return(new SqlServerConnection(options.ConnectionString));
            });
        }
Exemplo n.º 5
0
        public CapPublisher(IServiceProvider provider,
                            ILogger <CapPublisher> logger,
                            SqlServerOptions options)
        {
            ServiceProvider = provider;
            _logger         = logger;
            _options        = options;

            if (_options.DbContextType != null)
            {
                IsUsingEF  = true;
                _dbContext = (DbContext)ServiceProvider.GetService(_options.DbContextType);
            }
        }
Exemplo n.º 6
0
        private static void MigrateToLatest <TKey>(string connectionString, IdentityOptionsExtended identityOptions,
                                                   SqlServerOptions options) where TKey : IEquatable <TKey>
        {
            var runner = new MigrationRunner(connectionString, options);

            if (identityOptions.Stores.CreateIfNotExists)
            {
                runner.CreateDatabaseIfNotExistsAsync(CancellationToken.None).Wait();
            }

            if (identityOptions.Stores.MigrateOnStartup)
            {
                runner.MigrateUp(CancellationToken.None);
            }
        }
Exemplo n.º 7
0
        public CapPublisher(ILogger <CapPublisher> logger, IDispatcher dispatcher,
                            IServiceProvider provider, SqlServerOptions options)
            : base(logger, dispatcher)
        {
            ServiceProvider = provider;
            _options        = options;

            if (_options.DbContextType == null)
            {
                return;
            }

            IsUsingEF  = true;
            _dbContext = (DbContext)ServiceProvider.GetService(_options.DbContextType);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContextPool <AuthenticationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), SqlServerOptions =>
            {
                SqlServerOptions.MigrationsAssembly("Auth.DATA");
            }));

            services.AddIdentity <ApplicationUser, IdentityRole>().AddEntityFrameworkStores <AuthenticationDbContext>().AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            });

            services.AddControllers();

            services.AddTransient <IAuthService, AuthService>();
        }
Exemplo n.º 9
0
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            base.AddInternal(builder);

            var sqlServerOptions = new SqlServerOptions
            {
                ConnectionStringName = this.ConnectionStringName,
                MigrationsAssembly   = this.MigrationsAssembly,
                Options = this.Options
            };

            var sqlServerCacheOptions = new SqlServerCacheOptions();

            sqlServerOptions.BindSqlServerCacheOptions(builder.Configuration, sqlServerCacheOptions);

            builder.Services.AddDbContextFactory <SqlServerCacheContext>(optionsBuilder =>
            {
                optionsBuilder.UseSqlServer(sqlServerCacheOptions.ConnectionString,
                                            options =>
                {
                    if (this.MigrationsAssembly != null)
                    {
                        options.MigrationsAssembly(this.MigrationsAssembly);
                    }
                });
            });

            builder.Services.AddSingleton <IDistributedCache, DateTimeOffsetCacheMock>();

            builder.Services.Configure <DateTimeOffsetCacheOptionsMock>(options =>
            {
                this.Options?.Bind(options);
            });
        }
Exemplo n.º 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContextPool <ApplicationDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("ApplicationConnection"),
                                                SqlServerOptions => {
                SqlServerOptions.MigrationsAssembly("DretBlog.Data");
            }
                                                )
                );

            services.AddDbContextPool <AuthenticationDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("AuthenticationConnection"),
                                                SqlServerOptions => {
                SqlServerOptions.MigrationsAssembly("DretBlog.Data");
            })
                );

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AuthenticationDbContext>()
            .AddDefaultTokenProviders();

            //delibrate password weakening
            services.Configure <IdentityOptions>(options =>
            {
                options.SignIn.RequireConfirmedAccount     = false;
                options.SignIn.RequireConfirmedEmail       = false;
                options.SignIn.RequireConfirmedPhoneNumber = false;
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            });

            services.AddTransient <IAccountsServices, AccountsServices>();
            services.AddScoped <IDashboardServices, DashboardServices>();
            services.AddScoped <IPostsServices, PostsServices>();
            services.AddScoped <IBlogContentServices, BlogContentServices>();

            services.AddControllersWithViews();
        }
Exemplo n.º 11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            //用户需要配置的路由
            services.AddSingleton <IVirtualRoute <LogMessage>, LogMessageRoute>();

            var options = new SqlServerOptions()
            {
            };

            services.AddSingleton(options);
            services.AddScoped <IRepository, DefaultRepository>();
            services.AddSingleton <IShardingDbContextProvider, ShardingDbContextProvider>();
            services.AddSingleton <IVirtualTableManager, OneDbVirtualTableManager>();
            services.AddSingleton(typeof(IVirtualTable <>), typeof(OneDbVirtualTable <>));
            services.AddSingleton <ShardingBootstrapper>();
            var dbContextOptions = new DbContextOptionsBuilder()
                                   .UseSqlServer(options.ConnectionString)
                                   .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                                   .ReplaceService <IModelCacheKeyFactory, ShardingModelCacheKeyFactory>()
                                   .Options;

            services.AddSingleton(dbContextOptions);
        }
Exemplo n.º 12
0
        public static string GetConnectionString(this SqlServerOptions sqlServerOptions)
        {
            var builder = new SqlConnectionStringBuilder
            {
                ConnectTimeout           = sqlServerOptions.ConnectTimeout,
                DataSource               = sqlServerOptions.DataSource,
                Encrypt                  = sqlServerOptions.Encrypt,
                InitialCatalog           = sqlServerOptions.InitialCatalog,
                IntegratedSecurity       = sqlServerOptions.IntegratedSecurity,
                MultipleActiveResultSets = sqlServerOptions.MultipleActiveResultSets,
                PersistSecurityInfo      = sqlServerOptions.PersistSecurityInfo,
                TrustServerCertificate   = sqlServerOptions.TrustServerCertificate,
            };

            if (builder.IntegratedSecurity)
            {
                return(builder.ConnectionString);
            }

            builder.Password = sqlServerOptions.Password;
            builder.UserID   = sqlServerOptions.UserId;

            return(builder.ConnectionString);
        }
Exemplo n.º 13
0
 public TextRepository(IOptions <SqlServerOptions> options)
 {
     _configuration = options.Value;
 }
Exemplo n.º 14
0
 public JobsDbContext(DbContextOptions <JobsDbContext> options, SqlServerOptions sqlServerOptions)
     : base(options)
 {
     _sqlServerOptions = sqlServerOptions;
 }
Exemplo n.º 15
0
 public PersonRepository(IOptions <SqlServerOptions> sqlServerOptions)
 {
     _sqlServerOptions = sqlServerOptions.Value;
 }
Exemplo n.º 16
0
 public SqlServerMonitoringApi(IStorage storage, SqlServerOptions options)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
     _storage = storage as SqlServerStorage ?? throw new ArgumentNullException(nameof(storage));
 }
Exemplo n.º 17
0
 public SqlServerStorageConnection(SqlServerOptions options, CapOptions capOptions)
 {
     _capOptions = capOptions;
     Options     = options;
 }
 public ProductRepository(IOptions <SqlServerOptions> sqlServerOptions)
     : base(sqlServerOptions.Value.SqlServerConnection, sqlServerOptions.Value.ProductsTableName)
 {
     _sqlServerOptions = sqlServerOptions.Value;
 }
Exemplo n.º 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Esta línea configura AutoMapper
            services.AddAutoMapper(typeof(Startup));

            // Configuración servicio para subir archivos a StorageAzure

            /*
             * Si se van a subir a AzureStorage se debe descomentar la línea siguiente
             * services.AddTransient<IAlmacenadorArchivos, AlmacenadorArchivosAzure>();
             *
             *
             */
            // Configuración servicio para subir archivos al servidor
            services.AddTransient <IAlmacenadorArchivos, AlmacenadorArchivosLocal>();

            services.AddHttpContextAccessor();

            services.AddSingleton(NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326));

            services.AddSingleton(provider =>

                                  new MapperConfiguration(config =>
            {
                var geometryFactory = provider.GetRequiredService <GeometryFactory>();
                config.AddProfile(new AutoMapperProfiles(geometryFactory));
            }).CreateMapper()
                                  );


            // Configuración de la cadena de conexión
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                              SqlServerOptions => SqlServerOptions.UseNetTopologySuite()));

            services.AddControllers()
            .AddNewtonsoftJson();

            /*Configuración para la autenticación  */
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
                          options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(
                    Encoding.UTF8.GetBytes(Configuration["jwt:key"])),
                ClockSkew = TimeSpan.Zero
            }
                          );
        }
Exemplo n.º 20
0
 public MigrationRunner(string connectionString, SqlServerOptions options)
 {
     _connectionString = connectionString;
     _options          = options;
 }
Exemplo n.º 21
0
 public DefaultAdditionalProcessor(ILogger <DefaultAdditionalProcessor> logger,
                                   SqlServerOptions sqlServerOptions)
 {
     _logger  = logger;
     _options = sqlServerOptions;
 }
Exemplo n.º 22
0
 public SqlServerMonitoringApi(IOptions <SqlServerOptions> options, IStorageInitializer initializer)
 {
     _options = options.Value ?? throw new ArgumentNullException(nameof(options));
     _pubName = initializer.GetPublishedTableName();
     _recName = initializer.GetReceivedTableName();
 }
Exemplo n.º 23
0
 public SqlServerPublisher(IServiceProvider provider) : base(provider)
 {
     _options = ServiceProvider.GetService <SqlServerOptions>();
 }
Exemplo n.º 24
0
 public SqlServerStorageConnection(SqlServerOptions options)
 {
     _options = options;
 }
Exemplo n.º 25
0
 public SqlServerCollectProcessor(ILogger <SqlServerCollectProcessor> logger,
                                  SqlServerOptions sqlServerOptions)
 {
     _logger  = logger;
     _options = sqlServerOptions;
 }
Exemplo n.º 26
0
 public SqlServerStorage(ILogger <SqlServerStorage> logger, SqlServerOptions options)
 {
     _options = options;
     _logger  = logger;
 }
Exemplo n.º 27
0
 public SqlServerPublisher(IServiceProvider provider) : base(provider)
 {
     _options = ServiceProvider.GetService <IOptions <SqlServerOptions> >().Value;
 }
Exemplo n.º 28
0
 public SqlServerSagaPersistance(ISqlServerConnection sqlServerConnection, IDateTimeProvider dateTimeProvider, SqlServerOptions sqlServerOptions, IMessageBus messageBus)
 {
     this.instances                   = new Dictionary <Guid, string>();
     this.sqlServerConnection         = sqlServerConnection;
     this.dateTimeProvider            = dateTimeProvider;
     this.sqlServerOptions            = sqlServerOptions;
     this.weakInMemorySagaPersistance = new WeakInMemorySagaPersistance(
         TimeSpan.FromSeconds(15));
     this.messageBus = messageBus;
 }
Exemplo n.º 29
0
        public static IdentityBuilder AddSqlServerIdentityStore <TKey, TUser, TRole, TTenant>(
            this IdentityBuilder identityBuilder,
            string connectionString,
            ConnectionScope scope = ConnectionScope.ByRequest,
            Action <SqlServerOptions> configureDatabase = null)
            where TKey : IEquatable <TKey>
            where TUser : IdentityUserExtended <TKey>
            where TRole : IdentityRoleExtended <TKey>
            where TTenant : IdentityTenant <TKey>
        {
            var services = identityBuilder.Services;

            services.AddSingleton <ITypeRegistry, TypeRegistry>();

            var serviceProvider = services.BuildServiceProvider();

            var builder = new SqlConnectionStringBuilder(connectionString);

            void ConfigureAction(SqlServerOptions o)
            {
                configureDatabase?.Invoke(o);
            }

            identityBuilder.Services.Configure <SqlServerOptions>(ConfigureAction);

            var dialect = new SqlServerDialect();

            identityBuilder.AddSqlStores <SqlServerConnectionFactory, TKey, TUser, TRole, TTenant>(connectionString,
                                                                                                   scope, OnCommand <TKey>(), OnConnection);

            SqlBuilder.Dialect = dialect;

            SimpleDataDescriptor.TableNameConvention = s =>
            {
                switch (s)
                {
                case nameof(IdentityRoleExtended):
                    return("AspNetRoles");

                case nameof(IdentityUserExtended):
                    return("AspNetUsers");

                case nameof(IdentityTenant):
                    return("AspNetTenants");

                default:
                    return(s);
                }
            };

            DescriptorColumnMapper.AddTypeMap <TUser>(StringComparer.Ordinal);
            DescriptorColumnMapper.AddTypeMap <TRole>(StringComparer.Ordinal);
            DescriptorColumnMapper.AddTypeMap <TTenant>(StringComparer.Ordinal);

            services.AddMetrics();
            services.AddSingleton(dialect);

            identityBuilder.Services.AddSingleton <IQueryableProvider <TUser>, NoQueryableProvider <TUser> >();
            identityBuilder.Services.AddSingleton <IQueryableProvider <TRole>, NoQueryableProvider <TRole> >();
            identityBuilder.Services.AddSingleton <IQueryableProvider <TTenant>, NoQueryableProvider <TTenant> >();

            var options = new SqlServerOptions();

            ConfigureAction(options);

            var identityOptions = serviceProvider.GetRequiredService <IOptions <IdentityOptionsExtended> >().Value;

            MigrateToLatest <TKey>(connectionString, identityOptions, options);

            return(identityBuilder);
        }