public static IServiceLocator Services(Action<IContainerFacility> configure)
         {
             var facility = new StructureMapContainerFacility(new Container());
             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 myContainer = new Container();
            var myFacility = new StructureMapContainerFacility(myContainer);

            var registry = new TypeResolver();

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

            myFacility.BuildFactory();

            myContainer.GetInstance<ITypeResolver>().ShouldBeTheSameAs(registry);
        }
        public void should_register_an_endpoint_authorizor_if_there_are_any_authorization_rules()
        {
            var chain = new BehaviorChain();

            chain.AddToEnd(ActionCall.For <OneController>(x => x.Query(null)));
            chain.Authorization.AddRole("Role 1");
            chain.Prepend(chain.Authorization);

            var container = new Container();
            var facility  = new StructureMapContainerFacility(container);

            chain.As <IRegisterable>().Register(DiagnosticLevel.None, facility.Register);

            facility.BuildFactory();

            container.GetInstance <IEndPointAuthorizor>(chain.UniqueId.ToString())
            .ShouldNotBeNull().ShouldBeOfType <EndPointAuthorizor>();
        }
Exemple #4
0
        public void SetUp()
        {
            container = new Container(x =>
            {
                x.For <IFileSystem>().Use <FileSystem>();
                x.For <IStreamingData>().Use(MockRepository.GenerateMock <IStreamingData>());
                x.For <IHttpWriter>().Use(new NulloHttpWriter());
                x.For <ICurrentChain>().Use(new CurrentChain(null, null));
                x.For <ICurrentHttpRequest>().Use(new StandInCurrentHttpRequest()
                {
                    ApplicationRoot = "http://server"
                });

                x.For <IResourceHash>().Use(MockRepository.GenerateMock <IResourceHash>());
            });

            container.Configure(x => x.For <IContainerFacility>().Use <StructureMapContainerFacility>());


            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 StructureMapContainerFacility(container);
            graph.As <IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory();
        }
        public void SetUp()
        {
            container = new Container(x =>
            {
                x.For<IFileSystem>().Use<FileSystem>();
                x.For<IStreamingData>().Use(MockRepository.GenerateMock<IStreamingData>());
                x.For<IHttpWriter>().Use(new NulloHttpWriter());
                x.For<ICurrentChain>().Use(new CurrentChain(null, null));
                x.For<ICurrentHttpRequest>().Use(new StandInCurrentHttpRequest(){
                   
                    ApplicationRoot = "http://server"
                });

                x.For<IResourceHash>().Use(MockRepository.GenerateMock<IResourceHash>());
            });

            container.Configure(x => x.For<IContainerFacility>().Use<StructureMapContainerFacility>());


            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 StructureMapContainerFacility(container);
            graph.As<IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory();
        }
Exemple #6
0
        public void should_not_register_an_endpoint_authorizor_if_there_are_no_authorization_roles()
        {
            var chain = new BehaviorChain();

            chain.AddToEnd(ActionCall.For <OneController>(x => x.Query(null)));
            //chain.Authorization.AddRole("Role 1");

            var container = new Container();
            var facility  = new StructureMapContainerFacility(container);

            chain.As <IRegisterable>().Register(facility.Register);

            facility.BuildFactory();

            Debug.WriteLine(chain.UniqueId);
            Debug.WriteLine(container.WhatDoIHave());

            container.GetInstance <IEndPointAuthorizor>(chain.UniqueId.ToString())
            .ShouldBeOfType <NulloEndPointAuthorizor>();
        }
        public void SetUp()
        {
            container = new Container(x =>
            {
                x.For <IFileSystem>().Use <FileSystem>();
                x.For <IHttpResponse>().Use(new OwinHttpResponse());
                x.For <ICurrentChain>().Use(new CurrentChain(null, null));
                x.For <IHttpRequest>().Use(OwinHttpRequest.ForTesting());

                x.For <IResourceHash>().Use(MockRepository.GenerateMock <IResourceHash>());
            });

            container.Configure(x => x.For <IContainerFacility>().Use <StructureMapContainerFacility>());


            graph = BehaviorGraph.BuildFrom(x => {
                x.Actions.IncludeType <TestController>();

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

                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 StructureMapContainerFacility(container);
            graph.As <IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory(graph);
        }
        public void SetUp()
        {
            container = new Container(x =>
            {
                x.For<IFileSystem>().Use<FileSystem>();
                x.For<IHttpResponse>().Use(new OwinHttpResponse());
                x.For<ICurrentChain>().Use(new CurrentChain(null, null));
                x.For<IHttpRequest>().Use(OwinHttpRequest.ForTesting());

                x.For<IResourceHash>().Use(MockRepository.GenerateMock<IResourceHash>());
            });

            container.Configure(x => x.For<IContainerFacility>().Use<StructureMapContainerFacility>());

            graph = BehaviorGraph.BuildFrom(x => {
                x.Actions.IncludeType<TestController>();

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

                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 StructureMapContainerFacility(container);
            graph.As<IRegisterable>().Register(facility.Register);

            factory = facility.BuildFactory();
        }