private static IContainer CreateContainer()
 {
     var containerBuilder = new ContainerBuilder();
     containerBuilder.RegisterComponents();
     var container = containerBuilder.Build();
     return container;
 }
        public static IContainer Configure(string authToken, params Assembly[] assemblies)
        {
            IContainer container = null;

            var builder = new ContainerBuilder();

            builder.RegisterComponents(assemblies.SelectMany(asm => TryGetTypes(asm)))
                // Non-singleton components are registered as per-request.
                .ActivatorData.ConfigurationActions.Add((t, rb) =>
                {
                    // We know we have the ComponentAttribute since this is the result of RegisterComponents.
                    if (!rb.ActivatorData.ImplementationType.GetCustomAttributes(true).OfType<ComponentAttribute>().First().IsSingleton)
                        rb.InstancePerRequest();
                });

            builder.Register<IGitHubClient>(c =>
                new GitHubClient(
                    new ProductHeaderValue("OctoHook"),
                    new InMemoryCredentialStore(
                        new Credentials(authToken))));

            builder.Register<IApiConnection>(c =>
                new ApiConnection(c.Resolve<IGitHubClient>().Connection));

            container = builder.Build();

            return container;
        }
        private static IServiceLocator BuildLocator()
        {
            var builder = new ContainerBuilder();
            builder.RegisterComponents(typeof(IFoo).Assembly);

            var container = builder.Build();

            return new AutofacServiceLocator(container);
        }
        private static IComponentContext CreateRootContext()
        {
            var cb = new ContainerBuilder();

            cb.RegisterComponents(typeof(ComponentContext).Assembly);
            cb.RegisterType<BindingFactory>()
                .AsSelf()
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();

            var context = new ComponentContext(cb.Build());

            return context;
        }