Search This Blog

Thursday, July 21, 2011

Autofac listing components from a container taken from an assembly (Dll)

public interface A
{
    void p();
}

public class B : A
{
    public void p()
    { }
}

public class C : A
{
    public void p()
    { }
}

class Program
{
    static void Main()
    {
        var builder = new ContainerBuilder();
        var executingAssembly = Assembly.GetExecutingAssembly();
        var registrationBuilder = builder.RegisterAssemblyTypes(executingAssembly)
                            .Where(t => t.Name.Equals("C") || t.Name.Equals("B"))
                            .AsImplementedInterfaces().AsSelf();
        var container = builder.Build();
        var contList = container.Resolve<IEnumerable<A>>();

        Console.WriteLine("Done! Press any key.");
        Console.ReadKey();
    }
}

No comments:

Post a Comment

If you like this post, please leave a comment :)