コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddSingleton(Configuration);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient <IDapperContext>(p =>
            {
                var connection = PostgresConnection
                                 .Init()
                                 .SetarHost("localhost")
                                 .SetarUsuario("postgres")
                                 .SetarSenha("postgres")
                                 .SetarNomeBaseDeDados("bdgomi")
                                 .SetarPorta(5433)
                                 .Criar();

                if (!_iniciouBancoDados)
                {
                    var dbContext = new PostgresDbContext(connection);
                    dbContext.CreateDatabaseAsync(Assembly.GetAssembly(typeof(Versao))).Wait();
                    dbContext.ExecutarScriptsDaVersao();
                    _iniciouBancoDados = true;
                }

                return(new PostgresDbContext(connection));
            });

            services.AddTransient <ICaixaRepository, CaixaRepository>();
            services.AddTransient <ICentroCustoRepository, CentroCustoRepository>();
            services.AddTransient <IContaRepository, ContaRepository>();
            services.AddTransient <IEmpresaRepository, EmpresaRepository>();
            services.AddTransient <IPagarRepository, PagarRepository>();
            services.AddTransient <IPessoaRepository, PessoaRepository>();
            services.AddTransient <IPlanoContaRepository, PlanoContaRepository>();
            services.AddTransient <IReceberRepository, ReceberRepository>();
            services.AddTransient <ITransferenciaRepository, TransferenciaRepository>();
            services.AddTransient <IUsuarioRepository, UsuarioRepository>();

            services.AddSingleton <ICaixaService, CaixaService>();
            services.AddSingleton <ICentroCustoService, CentroCustoService>();
            services.AddSingleton <IContaService, ContaService>();
            services.AddSingleton <IDashboardService, DashboardService>();
            services.AddSingleton <IEmpresaService, EmpresaService>();
            services.AddSingleton <IPagarService, PagarService>();
            services.AddSingleton <IPessoaService, PessoaService>();
            services.AddSingleton <IPlanoContaService, PlanoContaService>();
            services.AddSingleton <IReceberService, ReceberService>();
            services.AddSingleton <ITransferenciaService, TransferenciaService>();
            services.AddSingleton <IUsuarioService, UsuarioService>();
            services.AddTransient <IPessoaService, PessoaService>();
        }