public static IServiceLocator Services(Action<IContainerFacility> configure)
        {
            var builder = new ContainerBuilder();
            var facility = new AutofacContainerFacility(builder.Build());
            configure(facility);

            // A ContainerFacility cannot be considered "ready" for business until BuildFactory() has been called.
            return facility.BuildFactory().Get<IServiceLocator>();
        }
示例#2
0
        public static IServiceLocator Services(Action <IContainerFacility> configure)
        {
            var builder  = new ContainerBuilder();
            var facility = new AutofacContainerFacility(builder.Build());

            configure(facility);

            // A ContainerFacility cannot be considered "ready" for business until BuildFactory() has been called.
            return(facility.BuildFactory().Get <IServiceLocator>());
        }
        public void register_a_service_by_value()
        {
            var builder = new ContainerBuilder();
            var myContext = builder.Build();
            var myFacility = new AutofacContainerFacility(myContext);

            var registry = new TypeResolver();

            myFacility.Register(
                typeof(ITypeResolver),
                new ObjectDef
                {
                    Value = registry
                });

            myFacility.BuildFactory();

            myContext.Resolve<ITypeResolver>().ShouldBeTheSameAs(registry);
        }
        public void register_a_service_by_value()
        {
            var builder    = new ContainerBuilder();
            var myContext  = builder.Build();
            var myFacility = new AutofacContainerFacility(myContext);

            var registry = new TypeResolver();

            myFacility.Register(
                typeof(ITypeResolver),
                new ObjectDef
            {
                Value = registry
            });

            myFacility.BuildFactory();

            myContext.Resolve <ITypeResolver>().ShouldBeTheSameAs(registry);
        }
        public void SetUp()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <FileSystem>().As <IFileSystem>();
            builder.RegisterInstance(MockRepository.GenerateMock <IStreamingData>()).As <IStreamingData>();
            builder.RegisterInstance(new NulloHttpWriter()).As <IHttpWriter>();
            builder.RegisterInstance(new CurrentChain(null, null)).As <ICurrentChain>();
            builder.RegisterInstance(
                new StandInCurrentHttpRequest
            {
                ApplicationRoot = "http://server"
            }).As <ICurrentHttpRequest>();
            builder.RegisterInstance(MockRepository.GenerateMock <IResourceHash>()).As <IResourceHash>();
            builder.RegisterType <AutofacContainerFacility>().As <IContainerFacility>();
            context = builder.Build();

            graph = BehaviorGraph.BuildFrom(
                x =>
            {
                x.Route("/area/sub/{Name}/{Age}")
                .Calls <TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route("/area/sub2/{Name}/{Age}")
                .Calls <TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route("/area/sub3/{Name}/{Age}")
                .Calls <TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Models.ConvertUsing <ExampleConverter>().ConvertUsing <ExampleConverter2>();


                x.Services(s => s.AddService <IActivator>(new StubActivator()));
                x.Services(s => s.AddService <IActivator>(new StubActivator()));
                x.Services(s => s.AddService <IActivator>(new StubActivator()));
            });

            facility = new AutofacContainerFacility(context);
            graph.As <IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory();
        }
        public void SetUp()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<FileSystem>().As<IFileSystem>();
            builder.RegisterInstance(MockRepository.GenerateMock<IStreamingData>()).As<IStreamingData>();
            builder.RegisterInstance(new NulloHttpWriter()).As<IHttpWriter>();
            builder.RegisterInstance(new CurrentChain(null, null)).As<ICurrentChain>();
            builder.RegisterInstance(
                new StandInCurrentHttpRequest
                {
                    ApplicationRoot = "http://server"
                }).As<ICurrentHttpRequest>();
            builder.RegisterInstance(MockRepository.GenerateMock<IResourceHash>()).As<IResourceHash>();
            builder.RegisterType<AutofacContainerFacility>().As<IContainerFacility>();
            context = builder.Build();

            graph = BehaviorGraph.BuildFrom(
                x =>
                {
                    x.Route("/area/sub/{Name}/{Age}")
                     .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                    x.Route("/area/sub2/{Name}/{Age}")
                     .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                    x.Route("/area/sub3/{Name}/{Age}")
                     .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                    x.Models.ConvertUsing<ExampleConverter>().ConvertUsing<ExampleConverter2>();

                    x.Services(s => s.AddService<IActivator>(new StubActivator()));
                    x.Services(s => s.AddService<IActivator>(new StubActivator()));
                    x.Services(s => s.AddService<IActivator>(new StubActivator()));
                });

            facility = new AutofacContainerFacility(context);
            graph.As<IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory();
        }