daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Autofac;
  2. using Autofac.Features.AttributeFilters;
  3. using NamedService.Database;
  4.  
  5. using static System.Console;
  6.  
  7. namespace NamedService
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var builder = new ContainerBuilder();
  14.  
  15.             builder.RegisterType<PostgresDatabase>()
  16.                 .Named<IDatabase>("postgres");
  17.  
  18.             builder.RegisterType<SqlServerDatabase>()
  19.                 .Named<IDatabase>("sql-server");
  20.  
  21.             using (IContainer container = builder.Build())
  22.             using (ILifetimeScope scope = container.BeginLifetimeScope())
  23.             {
  24.                 WriteLine("Resolving by name...");
  25.                 IDatabase database = scope.ResolveNamed<IDatabase>("postgres");
  26.                 database.Execute();
  27.             }
  28.         }
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top