Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autofac;
- namespace ConsoleApplication2
- {
- public abstract class ahah
- {
- public virtual void lel() { }
- }
- public class Lol : ahah
- {
- public override void lel()
- {
- Console.Write("Lol->lel");
- }
- }
- public class Lol2 : ahah
- {
- public override void lel()
- {
- Console.Write("Lol2->lel");
- }
- }
- public class Lol3 : ahah
- {
- public override void lel()
- {
- Console.Write("Lol3->lel");
- }
- }
- public interface LolMe
- {
- string omg { get; }
- }
- class Program
- {
- private readonly IEnumerable<Lazy<ahah, LolMe>> p;
- public Program(IEnumerable<Lazy<ahah, LolMe>> a)
- {
- p = a.Where(x => x.Metadata.omg == "LolMe");
- }
- static void Main(string[] args)
- {
- var builder = new ContainerBuilder();
- builder.RegisterType<Program>();
- builder.Register(c => new Lol()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe"));
- builder.Register(c => new Lol2()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe2"));
- builder.Register(c => new Lol3()).As<ahah>().WithMetadata<LolMe>(m => m.For(am => am.omg, "lolMe"));
- using (var container = builder.Build())
- {
- container.Resolve<Program>().Run();
- }
- }
- public void Run()
- {
- foreach (var b in p)
- {
- b.Value.lel();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement