Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var domainAssemblies = LoadAllDomainAssemblies().ToArray();

            services.AddServiced(domainAssemblies);

            services.AddControllers(options =>
            {
                var noContentFormatter = options.OutputFormatters
                                         .OfType <HttpNoContentOutputFormatter>()
                                         .FirstOrDefault();
                if (noContentFormatter != null)
                {
                    noContentFormatter.TreatNullValueAsNoContent = false;
                }
            });

            var swaggerOptions = new SwaggerOptions();

            ConfigureSwagger(swaggerOptions);
            services.AddSwaggerGen(c => { c.SwaggerDoc(swaggerOptions.SwaggerDocName, new OpenApiInfo {
                    Title = swaggerOptions.OpenApiTitle, Version = swaggerOptions.OpenApiVersion
                }); });

            services.AddAuthentication("IdentityBearer")
            .AddIdentityServerAuthentication("IdentityBearer",
                                             options =>
            {
                options.Authority            = "https://localhost:5005";
                options.RequireHttpsMetadata = false;
                options.RoleClaimType        = ClaimTypes.Role;
            });

            services.AddFluentMigratorCore()
            .ConfigureRunner(rb =>
            {
                ConfigureMigrator(rb);
                rb.ScanIn(domainAssemblies).For.Migrations();
            })
            .AddLogging(lb => lb.AddFluentMigratorConsole());

            var bus = RabbitHutch.CreateBus(Configuration.GetConnectionString("RabbitMQ"),
                                            svc => svc.EnableMessageVersioning());
            var rabbitMessageBus = new RabbitMqMessageBus(bus);

            services.AddSingleton <IMessageBus>(rabbitMessageBus);
            services.AddSingleton <RabbitScopedMessageDispatcher>();
            services.AddSingleton(p => new AutoSubscriber(rabbitMessageBus.Bus, MicroserviceName)
            {
                AutoSubscriberMessageDispatcher = new RabbitScopedMessageDispatcher(p)
            });

            RegisterServices(services);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.Add(new ServiceDescriptor(typeof(ICommandSender), typeof(CommandSender), ServiceLifetime.Transient));
            services.Add(new ServiceDescriptor(typeof(ISendEndpointProvider), typeof(RabbitMqEndpointProvider), ServiceLifetime.Transient));
            var rabbitMqMessageBus = new RabbitMqMessageBus(new RabbitMqConfiguration());

            services.Add(new ServiceDescriptor(typeof(IBusControl), rabbitMqMessageBus.Create()));
            services.Add(new ServiceDescriptor(typeof(IRabbitMqConfiguration), typeof(RabbitMqConfiguration), ServiceLifetime.Transient));
            services.Add(new ServiceDescriptor(typeof(ISendEndpointConfiguration), typeof(RabbitEndpointConfiguration), ServiceLifetime.Transient));
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
            
            services.AddDbContext<ApplicationDbContext>(options =>
                                                            options.UseSqlite(Configuration.GetConnectionString("SQLite"),
                                                                              o => o.MigrationsAssembly(migrationsAssembly)));

            services.AddIdentity<IdentityUser, IdentityRole>()
                    .AddEntityFrameworkStores<ApplicationDbContext>()
                    .AddDefaultTokenProviders();

            services.AddIdentityServer()
                    .AddDeveloperSigningCredential()
                    .AddInMemoryIdentityResources(Config.GetIdentityResources())
                    .AddInMemoryApiScopes(Config.GetApiScopes())
                    .AddInMemoryApiResources(Config.GetApiResources())
                    .AddInMemoryClients(Config.GetClients())
                    .AddAspNetIdentity<IdentityUser>();

            services.Configure<IdentityOptions>(options =>
                                                {
                                                    options.SignIn.RequireConfirmedAccount = false;
                                                    options.SignIn.RequireConfirmedEmail = false;
                                                    options.SignIn.RequireConfirmedPhoneNumber = false;

                                                    options.Password.RequireDigit = false;
                                                    options.Password.RequiredLength = 4;
                                                    options.Password.RequireLowercase = false;
                                                    options.Password.RequireUppercase = false;
                                                    options.Password.RequiredUniqueChars = 0;
                                                    options.Password.RequireNonAlphanumeric = false;

                                                    options.ClaimsIdentity.UserNameClaimType = ClaimTypes.Name;
                                                    options.ClaimsIdentity.RoleClaimType = ClaimTypes.Role;
                                                });

            services.AddControllers();

            var rabbitMessageBus = new RabbitMqMessageBus(RabbitHutch.CreateBus(Configuration.GetConnectionString("RabbitMQ")));
            services.AddSingleton<IMessageBus>(rabbitMessageBus);
        }