public IUserRepository Build(DatabaseEngine engine) { if (_configuration == null) { throw new InvalidOperationException("Configuration is not specified"); } var configurationService = new SystemConfigurationService(_configuration); var connectionService = new DatabaseConnectionService(configurationService); return(new UserRepository(connectionService)); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); try { DatabaseConnectionService db = new DatabaseConnectionService(); db.Connect(); Logger.Info("La base de datos se inicializó correctamente"); } catch (Exception ex) { Logger.Error("No se pudo inicializar la base de datos", ex); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Get the connection string from appsettings.json file. string connectionString = Configuration.GetConnectionString("DerafshConnectionString"); // Configure custom services to be used by the framework. var databaseConnectionService = new DatabaseConnectionService(connectionString); services.AddTransient <IDatabaseConnectionService>( e => databaseConnectionService ); services.AddTransient <IDatabaseActions, DatabaseActions>(); services.AddTransient <IIdentityRepository, IdentityRepository>(); services.AddTransient <ICityRepository, CityRepository>(); services.AddTransient <IStateRepository, StateRepository>(); services.AddTransient <ICountryRepository, CountryRepository>(); services.AddTransient <IAddressRepository, AddressRepository>(); services.AddTransient <IPhoneRepository, PhoneRepository>(); services.AddTransient <IEmailRepository, EmailRepository>(); }
private void ConnectDatabase() { DatabaseConnectionService connectionService = new DatabaseConnectionService(); connectionService.TryConnect(); }