Exemple #1
0
        protected override void ConfigureServicesInternal(IServiceCollection services)
        {
            services.AddSerilog(Configuration);

            services.AddSingleton <IHubConfiguration>(ServiceConfiguration);
            services.AddSingleton <IHubContextHolder <Trade>, HubContextHolder <Trade> >();
            services.AddSingleton <ICacheStrategy <MethodCacheObject>, DefaultCacheStrategy <MethodCacheObject> >();
            services.AddSingleton <ICacheStrategy <ResponseCacheEntry>, DefaultCacheStrategy <ResponseCacheEntry> >();
            services.AddTransient <IAuthorizationHandler, ClaimRequirementHandler>();
            services.AddSingleton <IMemoryCache, ResponseMemoryCache>();

            services.AddEventStore <Guid, EventStoreRepository <Guid> >(ServiceConfiguration.EventStore)
            .AddEventStoreCache <Guid, Trade>();

            services.AddSingleton <IHostedService, TradeEventListener>();

            services.AddConsulRegistration(ServiceConfiguration);

            services.AddSwagger(ServiceConfiguration);

            services.AddAuthorization(options =>
            {
                options.AddPolicy(TradeServiceReferential.TraderUserPolicy, policy => policy.Requirements.Add(new ClaimRequirement(ClaimTypes.Role, TradeServiceReferential.TraderClaimValue)));
            });

            var jsonSettings = new TradeServiceJsonSerializerSettings();

            services
            .AddSignalR(hubOptions =>
            {
                hubOptions.EnableDetailedErrors = true;
                hubOptions.KeepAliveInterval    = TimeSpan.FromMinutes(1);
            })
            .AddJsonProtocol(options =>
            {
                options.PayloadSerializerSettings = jsonSettings;
            });

            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ValidateModelStateAttribute));
            })
            .RegisterJsonSettings(jsonSettings)
            .AddFluentValidation(config => config.RegisterValidatorsFromAssemblies((assembly) => assembly.FullName.Contains("AzurePlayground.Service")));

            services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.RequireHttpsMetadata = false;
                options.Authority            = ServiceConfiguration.Identity;
                options.ApiName   = AzurePlaygroundConstants.Api.Trade;
                options.ApiSecret = ServiceConfiguration.Key;
            });
        }
Exemple #2
0
        protected override void ConfigureServicesInternal(IServiceCollection services)
        {
            services.AddSerilog(Configuration);
            services.AddSingleton <ICacheStrategy <MethodCacheObject>, DefaultCacheStrategy <MethodCacheObject> >();

            var database = MongoUrl.Create(ServiceConfiguration.MongoConnectionString).DatabaseName;

            var mongoDbContext = new MongoDbContext(ServiceConfiguration.MongoConnectionString, database);

            services.AddIdentity <ApplicationUser, ApplicationRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 1;
                options.Password.RequiredUniqueChars    = 1;
            })
            .AddMongoDbStores <IMongoDbContext>(mongoDbContext)
            .AddDefaultTokenProviders();

            services.AddIdentityServer(options =>
            {
                options.Events.RaiseSuccessEvents     = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
            })
            .AddMongoStores()
            .AddProfileService <AllAvailableClaimsProfileService>()
            .AddSigningCredential(IdentityServerBuilderExtensionsCrypto.CreateRsaSecurityKey())
            .Services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();

            services.AddAuthorization(options =>
            {
                options.AddPolicy(AzurePlaygroundConstants.Auth.AdminRolePolicy, policy => policy.RequireRole(AzurePlaygroundConstants.Auth.AdminRoleClaimValue));
            });

            services.AddSwagger(ServiceConfiguration);

            var jsonSettings = new TradeServiceJsonSerializerSettings();

            services.AddMvc()
            .RegisterJsonSettings(jsonSettings)
            .AddFluentValidation(config => config.RegisterValidatorsFromAssemblies((assembly) => assembly.FullName.Contains("AzurePlayground")));
        }
Exemple #3
0
        public AppRegistry()
        {
            For <ILogger>().Use <VoidLogger>();
            For <IHubConfiguration>().Use <AppConfiguration>();
            For <ISignalRService <Price, PriceRequest> >().Use <PriceHubClient>();
            For <ISignalRService <Trade, TradeEventRequest> >().Use <TradeEventHubClient>();

            var jsonSettings   = new TradeServiceJsonSerializerSettings();
            var jsonSerializer = JsonSerializer.Create(jsonSettings);

            For <JsonSerializerSettings>().Use(jsonSettings);
            For <JsonSerializer>().Use(jsonSerializer);

            Scan(scanner =>
            {
                scanner.AssembliesAndExecutablesFromApplicationBaseDirectory();
                scanner.WithDefaultConventions();
                scanner.ConnectImplementationsToTypesClosing(typeof(ISignalRService <,>));
            });
        }