Exemplo n.º 1
0
        public async Task <TResult> ExecuteQueryAsync <TResult>(IQuery <TResult> query)
        {
            using var scope = UserAccessCompositionRoot.BeginScope();
            var mediator = scope.ServiceProvider.GetService(typeof(IMediator)) as IMediator;

            return(await mediator.Send(query));
        }
Exemplo n.º 2
0
        private static void Initialize(IConfiguration configuration, ILogger logger)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(x => x.AddSerilog(logger));
            serviceCollection.AddSingleton(x => configuration.GetSection("AzureStorage").Get <AzureStorageConfiguration>());
            serviceCollection.AddSingleton(x => configuration.GetSection("Authentification").Get <AuthenticationConfiguration>());
            serviceCollection.AddTransient <IDateTimeProvider, DateTimeProvider>();
            serviceCollection.AddDbContext <DbContext, UserAccessContext>(options => options.UseSqlServer(configuration.GetConnectionString("UserAccessDbContext")));
            serviceCollection.AddScoped <IUserRepository, UserRepository>();
            serviceCollection.AddScoped <IDomainEventsDispatcher, DomainEventsDispatcher>();
            serviceCollection.AddScoped <IDomainEventsAccessor, DomainEventsAccessor>();
            serviceCollection.AddScoped <IStorageDomainEventsRepository, AzureStorageDomainEventsRepository>();
            serviceCollection.AddScoped <IHashPassword, Sha256HashPassword>();
            serviceCollection.AddScoped <ITokenGenerator, JwtTokenGenerator>();
            serviceCollection.AddScoped <IUnitOfWork, UnitOfWork>();
            serviceCollection.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehavior <,>));
            serviceCollection.AddTransient(typeof(IPipelineBehavior <,>), typeof(UnitOfWorkBehavior <,>));
            serviceCollection.AddMediatR(typeof(RegisterCommand).Assembly);
            UserAccessCompositionRoot.SetProvider(serviceCollection.BuildServiceProvider());
        }