Esempio n. 1
0
        public static AdventureContext CreateContext(DbConnection connection = null)
        {
            var builder = new DbContextOptionsBuilder <AdventureContext>();

            builder.UseSqlite(connection ?? AdventureContext.CreateInMemoryDatabase());
            builder.EnableSensitiveDataLogging(true);

            return(new AdventureContext(builder.Options));
        }
Esempio n. 2
0
        public RepositoryFixture()
        {
            _dbConnection = AdventureContext.CreateInMemoryDatabase();

            _services = new ServiceCollection();

            _services.AddDbContext <AdventureContext>(builder =>
                                                      builder.UseSqlite(_dbConnection));

            _services.AddUnitOfWork <AdventureContext>()
            .AddRepositories();
        }
Esempio n. 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            AddSwagger(services);

            AddAuthentication(services);

            #region Cors

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.SetIsOriginAllowedToAllowWildcardSubdomains()
                    .WithOrigins(Configuration.GetValue <string>("AllowedHosts").Split(','))
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            #endregion

            services.AddSingleton(AdventureContext.CreateInMemoryDatabase("RestAPI"));
            services.AddDbContext <AdventureContext>(
                (srv, builder) =>
            {
                var conn = srv.GetRequiredService <DbConnection>();
                builder.UseSqlite(conn);
            });

            services
            .AddUnitOfWork <AdventureContext>()
            .AddRepositories();

            services.AddAutoMapper(typeof(TestStub));

            services
            .AddControllers(options =>
            {
                options.Filters.Add <HttpResponseExceptionFilter>();
            })
            .AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining(typeof(TestStub)))
            .AddCybtansFormatter();

            services.AddOptions <JwtOptions>().Bind(Configuration.GetSection("Jwt"));

            services.AddCybtansServices(typeof(TestStub).Assembly);

            services.AddSingleton <EntityEventDelegateHandler <OrderMessageHandler> >();
            services.AddTransient <OrderMessageHandler>();
            services.AddMessageHandler <CustomerEvent, Customer>();

            services.AddMessageQueue(Configuration)
            .ConfigureSubscriptions(sm =>
            {
                sm.SubscribeHandlerForEvents <Order, OrderMessageHandler>("Test");
                sm.SubscribeForEvents <CustomerEvent, Customer>("Test");
            });

            services.AddDbContextEventPublisher <AdventureContext>();

            services.AddTransient <AdventureContextSeed>();
        }
Esempio n. 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            AddSwagger(services);

            AddAuthentication(services);

            #region Cors

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.SetIsOriginAllowedToAllowWildcardSubdomains()
                    .AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            #endregion

            #region Data Access Layer

            services.AddSingleton(AdventureContext.CreateInMemoryDatabase("RestAPI"));
            services.AddDbContext <AdventureContext>(
                (srv, builder) =>
            {
                var conn = srv.GetRequiredService <DbConnection>();
                builder.UseSqlite(conn);
            });

            services
            .AddUnitOfWork <AdventureContext>()
            .AddRepositories();

            services.AddTransient <AdventureContextSeed>();
            services.AddDatabaseConnectionFactory(o => o.ConnectionFactoryDelegate = () => AdventureContext.CreateInMemoryDatabase("RestAPI"));

            #endregion

            #region WebAPI

            services
            .AddControllers(options =>
            {
                options.Filters.Add <HttpResponseExceptionFilter>();
            })
            //.AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining(typeof(TestStub)))
            .AddCybtansFormatter();

            #endregion

            #region App Services

            services.AddOptions <JwtOptions>().Bind(Configuration.GetSection("Jwt"));
            services.AddAutoMapper(typeof(TestStub));
            services.AddCybtansServices(typeof(TestStub).Assembly);

            services.AddSingleton <EntityEventDelegateHandler <OrderMessageHandler> >();
            services.AddTransient <OrderMessageHandler>();
            services.AddMessageHandler <CustomerEvent, Customer>();
            services.AddDefaultValidatorProvider(p =>
            {
                p.AddValidatorFromAssembly(typeof(TestStub).Assembly);
            });
            services.AddSingleton <IMessageInterceptor, ValidatorActionInterceptor>();

            #endregion

            #region Messaging

            services.AddMessageQueue(Configuration)
            .ConfigureSubscriptions(sm =>
            {
                sm.SubscribeHandlerForEvents <Order, OrderMessageHandler>("Test");
                sm.SubscribeForEvents <CustomerEvent, Customer>("Test");
            });

            services.AddDbContextEventPublisher <AdventureContext>();

            services.AddAccessTokenManager(Configuration);

            services.AddBroadCastService(Configuration.GetSection("BroadCastOptions").Get <BroadcastServiceOptions>());
            #endregion

            #region Caching

            services.AddLocalCache();

            #endregion

            #region Grpc Clients

            //Add Grpc clients
            // This switch must be set before creating the GrpcChannel/HttpClient.
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            services.AddGrpcClient <Greeter.GreeterClient>(o =>
            {
                o.Address = new Uri(Configuration["GreteerService"]);
            });

            #endregion

            #region GraphQL

            services.AddSingleton <ISchema, TestQueryDefinitionsSchema>();
            services.AddGraphQL(options =>
            {
                options.EnableMetrics = true;
            })
            .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
            .AddSystemTextJson()
            .AddGraphTypes(typeof(Startup), ServiceLifetime.Singleton);

            #endregion
        }