using System; using System.Collections.Generic; using Kyoo.Controllers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Unity; namespace Kyoo.Postgresql { /// /// A module to add postgresql capacity to the app. /// public class PostgresModule : IPlugin { /// public string Slug => "postgresql"; /// public string Name => "Postgresql"; /// public string Description => "A database context for postgresql."; /// public ICollection Provides => new[] { typeof(DatabaseContext) }; /// public ICollection ConditionalProvides => ArraySegment.Empty; /// public ICollection Requires => ArraySegment.Empty; /// /// The configuration to use. The database connection string is pulled from it. /// private readonly IConfiguration _configuration; /// /// The host environment to check if the app is in debug mode. /// private readonly IWebHostEnvironment _environment; /// /// Create a new postgres module instance and use the given configuration and environment. /// /// The configuration to use /// The environment that will be used (if the env is in development mode, more information will be displayed on errors. public PostgresModule(IConfiguration configuration, IWebHostEnvironment env) { _configuration = configuration; _environment = env; } /// public void Configure(IUnityContainer container, ICollection availableTypes) { container.RegisterFactory(_ => new PostgresContext( _configuration.GetDatabaseConnection("postgres"), _environment.IsDevelopment())); } } }