Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autofac;
  6. namespace ConsoleApplication2
  7. {
  8.     public abstract class ahah
  9.     {
  10.         public virtual void lel() { }
  11.     }
  12.  
  13.     public class Lol : ahah
  14.     {
  15.         public override void lel()
  16.         {
  17.             Console.Write("Lol->lel");
  18.         }
  19.     }
  20.  
  21.     public class Lol2 : ahah
  22.     {
  23.         public override void lel()
  24.         {
  25.             Console.Write("Lol2->lel");
  26.         }
  27.     }
  28.  
  29.     public class Lol3 : ahah
  30.     {
  31.         public override void lel()
  32.         {
  33.             Console.Write("Lol3->lel");
  34.         }
  35.     }
  36.  
  37.     public interface LolMe
  38.     {
  39.         string omg { get; }
  40.     }
  41.  
  42.     class Program
  43.     {
  44.         private readonly IEnumerable<Lazy<ahah, LolMe>> p;
  45.  
  46.         public Program(IEnumerable<Lazy<ahah, LolMe>> a)
  47.         {
  48.             p = a.Where(x => x.Metadata.omg == "LolMe");
  49.         }
  50.  
  51.         static void Main(string[] args)
  52.         {
  53.             var builder = new ContainerBuilder();
  54.  
  55.             builder.RegisterType<Program>();
  56.             builder.Register(c => new Lol()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe"));
  57.             builder.Register(c => new Lol2()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe2"));
  58.             builder.Register(c => new Lol3()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe"));
  59.  
  60.             using (var container = builder.Build())
  61.             {
  62.                 container.Resolve<Program>().Run();
  63.             }
  64.         }
  65.  
  66.         public void Run()
  67.         {
  68.             foreach (var b in p)
  69.             {
  70.                 b.Value.lel();
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement