Ejemplo n.º 1
0
        protected IPipeline CreatePipeline(Type callGraphGeneratorType, Type[] contributorTypes)
        {
            var resolver = new InternalDependencyResolver();

            resolver.AddDependencyInstance <IDependencyResolver>(resolver);
            resolver.AddDependency <IPipelineContributor, BootstrapperContributor>();
            resolver.AddDependency <T>();
            //resolver.AddDependency<IPipeline, T>(DependencyLifetime.Singleton);


            if (callGraphGeneratorType != null)
            {
                resolver.AddDependency(typeof(IGenerateCallGraphs), callGraphGeneratorType, DependencyLifetime.Singleton);
            }

            foreach (var type in contributorTypes)
            {
                resolver.AddDependency(typeof(IPipelineContributor), type, DependencyLifetime.Singleton);
            }

            var runner = resolver.Resolve <T>();

            runner.Initialize();
            return(runner);
        }
Ejemplo n.º 2
0
        public void logging_is_not_injected()
        {
            IDependencyResolver resolver = new InternalDependencyResolver();

            resolver.AddDependency <IGenerateCallGraphs, TopologicalSortCallGraphGenerator>();
            resolver.AddDependency <IPipelineContributor, BootstrapperContributor>();
            resolver.AddDependency <IPipelineContributor, First>();
            var initialiser = new ThreePhasePipelineInitializer(
                resolver.Resolve <IEnumerable <IPipelineContributor> >(),
                resolver.Resolve <IGenerateCallGraphs>());

            var props = new StartupProperties
            {
                OpenRasta =
                {
                    Diagnostics = { TracePipelineExecution = false },
                    Pipeline    = { Validate               = false }
                }
            };

            var pipeline = initialiser
                           .Initialize(props);

            pipeline.MiddlewareFactories
            .ShouldNotContain(factory => factory is LoggingMiddlewareFactory);
        }
 public MyOpenRastaDependencyResolverAccessor()
 {
     var resolver = new InternalDependencyResolver();
     resolver.AddDependency<OwinCommunicationContext>(DependencyLifetime.PerRequest);
     resolver.AddDependency<IValidator<Widget>, RulesForWidgetRequests>(DependencyLifetime.PerRequest);
     _resolver = resolver;
 }
        protected static IPipelineAsync CreatePipeline(
            Type callGraphGeneratorType,
            Type[] contributorTypes,
            Action <StartupProperties> options = null)
        {
            var resolver = new InternalDependencyResolver();

            resolver.AddDependencyInstance <IDependencyResolver>(resolver);
            resolver.AddDependency <IPipelineInitializer, ThreePhasePipelineInitializer>();
            resolver.AddDependency(typeof(IGenerateCallGraphs), callGraphGeneratorType, DependencyLifetime.Transient);

            if (callGraphGeneratorType != null)
            {
                resolver.AddDependency(typeof(IGenerateCallGraphs), callGraphGeneratorType,
                                       DependencyLifetime.Singleton);
            }

            foreach (var type in contributorTypes)
            {
                resolver.AddDependency(typeof(IPipelineContributor), type, DependencyLifetime.Singleton);
            }

            var runner = resolver.Resolve <IPipelineInitializer>();


            var opt = new StartupProperties {
                OpenRasta = { Pipeline = { Validate = true } }
            };

            options?.Invoke(opt);
            return(runner.Initialize(opt));
        }
Ejemplo n.º 5
0
        public void logging_is_injected()
        {
            IDependencyResolver resolver = new InternalDependencyResolver();

            resolver.AddDependency <IGenerateCallGraphs, TopologicalSortCallGraphGenerator>();
            resolver.AddDependency <IPipelineContributor, PreExecutingContributor>();
            resolver.AddDependency <IPipelineContributor, First>();
            var initialiser = new ThreePhasePipelineInitializer(
                resolver.Resolve <IEnumerable <IPipelineContributor> >(),
                resolver.Resolve <IGenerateCallGraphs>());

            var pipeline = initialiser
                           .Initialize(new StartupProperties
            {
                OpenRasta =
                {
                    Diagnostics = { TracePipelineExecution = true  },
                    Pipeline    = { Validate               = false }
                }
            });

            var factories = pipeline.MiddlewareFactories
                            .Where((factory, i) => i % 2 == 0)
                            .ToList();

            factories.Count().ShouldBe(pipeline.MiddlewareFactories.Count() / 2);
            factories.ShouldAllBe(factory => factory is LoggingMiddlewareFactory);
        }
 public registration_depending_on_func_of_unregistered_after_registration()
 {
     resolver = new InternalDependencyResolver();
     resolver.AddDependency <DependsOnFuncOfSimple>();
     instance = resolver.Resolve <DependsOnFuncOfSimple>();
     resolver.AddDependency <Simple>();
 }
Ejemplo n.º 7
0
        public MyOpenRastaDependencyResolverAccessor()
        {
            var resolver = new InternalDependencyResolver();

            resolver.AddDependency <OwinCommunicationContext>(DependencyLifetime.PerRequest);
            resolver.AddDependency <IValidator <Widget>, RulesForWidgetRequests>(DependencyLifetime.PerRequest);
            _resolver = resolver;
        }
Ejemplo n.º 8
0
        private void OpenRastaRegistrar(CommandProcessor commandProcessor)
        {
            _internalDependencyResolver = new InternalDependencyResolver();

            _internalDependencyResolver.AddDependencyInstance <IAmACommandProcessor>(commandProcessor, DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency <ITaskRetriever, TaskRetriever>(DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency <ITaskListRetriever, TaskListRetriever>(DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency <ITasksDAO, TasksDAO>(DependencyLifetime.Singleton);
        }
 public override void CreateContext()
 {
     base.CreateContext();
     this.sparkConfiguration = new SparkConfiguration();
     var resolver = new InternalDependencyResolver();
     resolver.AddDependency(typeof(IUriResolver), typeof(TestUriResolver), DependencyLifetime.Singleton);
     resolver.AddDependency(
         typeof(ICommunicationContext), typeof(TestCommunicationContext), DependencyLifetime.Singleton);
     DependencyManager.SetResolver(resolver);
 }
Ejemplo n.º 10
0
        public override void CreateContext()
        {
            base.CreateContext();
            var resolver = new InternalDependencyResolver();

            resolver.AddDependency(typeof(IUriResolver), typeof(TestUriResolver), DependencyLifetime.Singleton);
            resolver.AddDependency(typeof(ICommunicationContext), typeof(TestCommunicationContext),
                                   DependencyLifetime.Singleton);
            DependencyManager.SetResolver(resolver);
        }
Ejemplo n.º 11
0
        public void CanRegisterMultipleDispensers()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<IJellybeanDispenser, VanillaJellybeanDispenser>();
            container.AddDependency<IJellybeanDispenser, StrawberryJellybeanDispenser>();

            IEnumerable<IJellybeanDispenser> dispensers = container.ResolveAll<IJellybeanDispenser>();

            Assert.IsNotNull(dispensers);
            Assert.AreEqual(2, dispensers.Count());
        }
Ejemplo n.º 12
0
        public void CanMakeSweetShopWithVanillaJellybeans()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop>();
            container.AddDependency<SweetVendingMachine>();
            container.AddDependency<IJellybeanDispenser, VanillaJellybeanDispenser>();

            SweetShop sweetShop = container.Resolve<SweetShop>();

            Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean());
        }
Ejemplo n.º 13
0
        public void CanMakeSingletonJellybeanDispenser()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop>(DependencyLifetime.Transient);
            container.AddDependency<SweetVendingMachine>(DependencyLifetime.Transient);
            container.AddDependency<IJellybeanDispenser, StrawberryJellybeanDispenser>(DependencyLifetime.Singleton);

            SweetShop sweetShop = container.Resolve<SweetShop>();
            SweetShop sweetShop2 = container.Resolve<SweetShop>();

            Assert.AreNotSame(sweetShop, sweetShop2, "Root objects are equal");
            Assert.AreNotSame(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine, "Contained objects are equal");

            // should be same service
            Assert.AreSame(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser, "services are not equal");
        }
        public void func_is_resolved()
        {
            var resolver = new InternalDependencyResolver();
            var factory  = resolver.Resolve <Func <IEnumerable <Simple> > >();

            resolver.AddDependency <Simple>();
            factory().ShouldHaveSingleItem().ShouldNotBeNull();
        }
Ejemplo n.º 15
0
        protected IPipeline CreatePipeline(params Type[] contributorTypes)
        {
            var resolver = new InternalDependencyResolver();

            resolver.AddDependency <IPipelineContributor, BootstrapperContributor>();
            foreach (var type in contributorTypes)
            {
                resolver.AddDependency(typeof(IPipelineContributor), type, DependencyLifetime.Singleton);
            }
            var runner = new PipelineRunner(resolver)
            {
                PipelineLog = new TraceSourceLogger <PipelineLogSource>()
            };

            runner.Initialize();
            return(runner);
        }
Ejemplo n.º 16
0
        public void CanMakeAniseedRootObject()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop, AniseedSweetShop>();

            SweetShop sweetShop = container.Resolve<SweetShop>();

            Assert.AreEqual(Jellybean.Aniseed, sweetShop.DispenseJellyBean());
        }
        public void resolve_succeeds()
        {
            var resolver = new InternalDependencyResolver();

            resolver.AddDependency <IContextStore, AmbientContextStore>();

            resolver.AddDependency <Contributor>(DependencyLifetime.Singleton);
            resolver.AddDependency <ErrorCollector>(DependencyLifetime.Transient);

            var contributor = resolver.Resolve <Contributor>();

            using (new ContextScope(new AmbientContext()))
                using (resolver.CreateRequestScope())
                {
                    resolver.AddDependencyInstance(new Request(), DependencyLifetime.PerRequest);
                    var result = contributor.Factory();
                    result.ShouldHaveSingleItem();
                }
        }
Ejemplo n.º 18
0
        protected override void SetUp()
        {
            base.SetUp();
            var resolver = new InternalDependencyResolver();

            DependencyManager.SetResolver(resolver);
            resolver.AddDependency <IUriResolver, TemplatedUriResolver>();
            resolver.AddDependencyInstance <IDependencyResolver>(resolver);
            UriResolver = DependencyManager.GetService <IUriResolver>();
        }
        public with_per_request_dependency()
        {
            Resolver = new InternalDependencyResolver()
                       .Singleton <IContextStore, InMemoryContextStore>();

            Resolver.AddDependency <IOperationInterceptor, SystemAttribute>(DependencyLifetime.PerRequest);

            var mi = HandlerMethodVisitor.FindMethodInfo <Handler>(h => h.Get());

            var creator = new MethodBasedOperationCreator(
                resolver: Resolver,
                syncInterceptorProvider:
                new SystemAndAttributesOperationInterceptorProvider(Resolver.Resolve <IEnumerable <IOperationInterceptor> >));

            Resolver.AddDependency <IMyService, Service>(DependencyLifetime.PerRequest);

            var value = creator
                        .CreateOperation(TypeSystems.Default.FromClr <Handler>(), TypeSystems.Default.From(mi))
                        .InvokeAsync()
                        .Result.ToList();
        }
Ejemplo n.º 20
0
        private void OpenRastaRegistrar(CommandProcessor commandProcessor)
        {
            _internalDependencyResolver = new InternalDependencyResolver();

            _internalDependencyResolver.AddDependencyInstance<IAmACommandProcessor>(commandProcessor, DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency<ITaskRetriever, TaskRetriever>(DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency<ITaskListRetriever, TaskListRetriever>(DependencyLifetime.Singleton);
            _internalDependencyResolver.AddDependency<ITasksDAO, TasksDAO>(DependencyLifetime.Singleton);
        }
Ejemplo n.º 21
0
 public registration_profiles()
 {
     resolver = new InternalDependencyResolver();
     resolver.AddDependency <Simple>();
 }
Ejemplo n.º 22
0
        public void CanUseObjectFactory()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop>(DependencyLifetime.Transient);
            container.AddDependency<SweetVendingMachine>(DependencyLifetime.Transient);
            container.AddDependency<IJellybeanDispenser>(c => new AnyJellybeanDispenser(Jellybean.Orange));

            SweetShop sweetShop = container.Resolve<SweetShop>();

            Assert.AreEqual(Jellybean.Orange, sweetShop.DispenseJellyBean());
        }
Ejemplo n.º 23
0
        public void CanUseObjectFactoryWithSingleton()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop>(DependencyLifetime.Transient);
            container.AddDependency<SweetVendingMachine>(DependencyLifetime.Transient);

            IJellybeanDispenser instance = new AnyJellybeanDispenser(Jellybean.Orange);
            // The lambda captures the instance and uses it across multiple calls. It's a singleton
            container.AddDependency<IJellybeanDispenser>(c => instance);

            SweetShop sweetShop = container.Resolve<SweetShop>();
            SweetShop sweetShop2 = container.Resolve<SweetShop>();

            Assert.AreEqual(Jellybean.Orange, sweetShop.DispenseJellyBean());
            Assert.AreEqual(Jellybean.Orange, sweetShop2.DispenseJellyBean());

            Assert.AreNotSame(sweetShop, sweetShop2, "Root objects are equal");
            Assert.AreNotSame(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine, "Contained objects are equal");

            // should be same service
            Assert.AreSame(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser, "services are not equal");
        }
Ejemplo n.º 24
0
        public void JellybeanDispenserHasNewInstanceEachTime()
        {
            IDependencyResolver container = new InternalDependencyResolver();

            // default is " DependencyLifetime.Singleton" so specify transient objects
            container.AddDependency<SweetShop>(DependencyLifetime.Transient);
            container.AddDependency<SweetVendingMachine>(DependencyLifetime.Transient);
            container.AddDependency<IJellybeanDispenser, VanillaJellybeanDispenser>(DependencyLifetime.Transient);

            SweetShop sweetShop = container.Resolve<SweetShop>();
            SweetShop sweetShop2 = container.Resolve<SweetShop>();

            Assert.AreNotSame(sweetShop, sweetShop2, "Root objects are equal");
            Assert.AreNotSame(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine, "Contained objects are equal");
            Assert.AreNotSame(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser, "services are equal");
        }
Ejemplo n.º 25
0
        public void CanUseConstructedObject()
        {
            IDependencyResolver container = new InternalDependencyResolver();
            container.AddDependency<SweetShop>(DependencyLifetime.Transient);
            container.AddDependency<SweetVendingMachine>(DependencyLifetime.Transient);
            container.AddDependencyInstance<IJellybeanDispenser>(new AnyJellybeanDispenser(Jellybean.Cocoa));

            SweetShop sweetShop = container.Resolve<SweetShop>();

            Assert.AreEqual(Jellybean.Cocoa, sweetShop.DispenseJellyBean());
        }
 public registration_depending_on_func_of_unregistered()
 {
     resolver = new InternalDependencyResolver();
     resolver.AddDependency <DependsOnFuncOfSimple>();
 }