Aliendreamer

depedency resolver dynamic asp net core

Sep 11th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1.   public class DependencyResolver
  2.     {
  3.         /// <summary>
  4.         /// Applies the configuration.
  5.         /// </summary>
  6.         /// <param name="services">The services.</param>
  7.         /// <param name="configuration">The configuration.</param>
  8.         public static void ApplyConfig(IServiceCollection services, IConfiguration configuration)
  9.         {
  10.             services.AddSingleton<IAppSettingsProvider>(provider => new AppSettingsProvider(configuration));
  11.             services.AddTransient<IInvoiceInfoRepository, InvoiceInfoRepository>();
  12.             services.AddTransient<IInvoiceStatusRepository, InvoiceStatusRepository>();
  13.  
  14.             services.AddTransient<IInvoiceService, InvoiceService>();
  15.             services.AddTransient<IInvoiceUnitOfWork, InvoiceUnitOfWork>();
  16.             services.AddTransient<ITibcoRepository, TibcoRepository>();
  17.             services.AddTransient<IRequestUnitOfWork, RequestUnitOfWork>();
  18.         }
  19.     }
  20.  
  21.  public class AppSettingsProvider : IAppSettingsProvider
  22.     {
  23.         private readonly IConfiguration configuration;
  24.  
  25.         /// <summary>
  26.         /// Initializes a new instance of the <see cref="AppSettingsProvider"/> class.
  27.         /// </summary>
  28.         /// <param name="configuration">The configuration.</param>
  29.         public AppSettingsProvider(IConfiguration configuration)
  30.         {
  31.             this.configuration = configuration;
  32.         }
  33.  
  34.         public string PostgresConnectionString => this.configuration[AppSettingsConstants.DbConnectionString];
  35.  
  36.         public string TibcoUrl => this.configuration[AppSettingsConstants.TibcoUrl];
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment