public void build_an_object_with_dependencies()
        {
            var request = new InMemoryFubuRequest();


            var def = new ObjectDef(typeof(FakeJsonBehavior));

            def.DependencyByValue(typeof(IFubuRequest), request);
            var jsonWriter = def.DependencyByType(typeof(IJsonWriter), typeof(AjaxAwareJsonWriter));

            jsonWriter.DependencyByType(typeof(IOutputWriter), typeof(OutputWriter));
            jsonWriter.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData));
            def.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData));

            var container =
                new Container(x =>
            {
                x.For <IFileSystem>().Use <FileSystem>();
                x.For <IHttpWriter>().Use <NulloHttpWriter>();
                x.For <IActionBehavior>().Use(new ObjectDefInstance(def));
                x.For <ILogger>().Use <Logger>();
                x.For <ISystemTime>().Use(SystemTime.Default);
            });

            var jsonBehavior = container.GetInstance <IActionBehavior>().ShouldBeOfType <FakeJsonBehavior>();

            jsonBehavior.Writer.ShouldBeOfType <AjaxAwareJsonWriter>();
            jsonBehavior.Request.ShouldBeTheSameAs(request);
        }
        public void build_an_object_with_dependencies()
        {
            var request = new InMemoryFubuRequest();


            var def = new ObjectDef(typeof (FakeJsonBehavior));
            def.DependencyByValue(typeof (IFubuRequest), request);
            var jsonWriter = def.DependencyByType(typeof (IJsonWriter), typeof (AjaxAwareJsonWriter));
            jsonWriter.DependencyByType(typeof (IOutputWriter), typeof (OutputWriter));
            jsonWriter.DependencyByType(typeof(IRequestData), typeof(InMemoryRequestData));
            def.DependencyByType(typeof (IRequestData), typeof (InMemoryRequestData));

            var container =
                new Container(x =>
                {
                    x.For<IFileSystem>().Use<FileSystem>();
                    x.For<IHttpWriter>().Use<NulloHttpWriter>();
                    x.For<IActionBehavior>().UseInstance(new ObjectDefInstance(def));
                    x.For<ILogger>().Use<Logger>();
                    x.For<ISystemTime>().Use(() => SystemTime.Default());
                });

            var jsonBehavior = container.GetInstance<IActionBehavior>().ShouldBeOfType<FakeJsonBehavior>();
            jsonBehavior.Writer.ShouldBeOfType<AjaxAwareJsonWriter>();
            jsonBehavior.Request.ShouldBeTheSameAs(request);
        }
Beispiel #3
0
        private ObjectDef buildObjectDef(DiagnosticLevel diagnosticLevel)
        {
            var topDef = Top.As <IContainerModel>().ToObjectDef(diagnosticLevel);

            if (diagnosticLevel == DiagnosticLevel.FullRequestTracing && !IsPartialOnly)
            {
                var objectDef = new ObjectDef(typeof(DiagnosticBehavior))
                {
                    Name = UniqueId.ToString()
                };

                objectDef.DependencyByType <IActionBehavior>(topDef);

                topDef.Name = Guid.NewGuid().ToString();

                var list = new List <ObjectDef>();
                var def  = topDef;
                while (def != null)
                {
                    list.Add(def);
                    def = def.FindDependencyDefinitionFor <IActionBehavior>();
                }

                return(objectDef);
            }

            return(topDef);
        }
Beispiel #4
0
 protected override void configure(ObjectDef def)
 {
     if (_membershipType != null)
     {
         def.DependencyByType <IMembershipRepository>(new ObjectDef(_membershipType));
     }
 }
Beispiel #5
0
        protected override ObjectDef toWriterDef()
        {
            var def = new ObjectDef(typeof(ViewWriter<>), ResourceType);

            def.DependencyByType<IViewFactory>(_token.ToViewFactoryObjectDef());

            return def;
        }
Beispiel #6
0
        protected override ObjectDef toWriterDef()
        {
            var def = new ObjectDef(typeof(ViewWriter <>), ResourceType);

            def.DependencyByType <IViewFactory>(_token.ToViewFactoryObjectDef());

            return(def);
        }
Beispiel #7
0
        public ObjectDef ToObjectDef(DiagnosticLevel level)
        {
            var objectDef = new ObjectDef(typeof(FeedWriter <T>));

            objectDef.DependencyByType(typeof(IFeedSource <T>), FeedSourceType);
            objectDef.DependencyByValue(typeof(IFeedDefinition <T>), _feed);

            return(objectDef);
        }
Beispiel #8
0
        protected override void configureObject(ObjectDef def)
        {
            var renderer = def.DependencyByType(typeof(IViewRenderer), typeof(ViewRenderer));

            var viewEntrySource = renderer.DependencyByType(typeof(IRenderAction), typeof(RenderAction))
                                  .DependencyByType(typeof(IViewFactory), typeof(ViewFactory))
                                  .DependencyByType(typeof(IViewEntrySource), typeof(ViewEntrySource));

            viewEntrySource.DependencyByValue(_descriptor);
        }
Beispiel #9
0
        protected ObjectDef toObjectDef()
        {
            ObjectDef objectDef = buildObjectDef();

            if (Next != null)
            {
                var nextObjectDef = Next.As <IContainerModel>().ToObjectDef();
                objectDef.DependencyByType <IActionBehavior>(nextObjectDef);
            }

            return(objectDef);
        }
Beispiel #10
0
        ObjectDef IContainerModel.ToObjectDef()
        {
            var def = new ObjectDef(typeof(Media <>), ResourceType);

            def.DependencyByType <IConditional>(_conditionalDef);

            var writerType = typeof(IMediaWriter <>).MakeGenericType(ResourceType);

            // TODO -- validate that it's really an IMediaWriter<T>
            def.Dependency(writerType, toWriterDef());

            return(def);
        }
Beispiel #11
0
 protected override ObjectDef BuildObjectDef()
 {
     var messageType = Chain.MessageType;
     var handlerDef = new ObjectDef(typeof (ConditionalHandler<>), messageType);
     var dependencyType = typeof (ICondition<>).MakeGenericType(messageType);
     var conditionType = ConditionType;
     if(conditionType.IsOpenGeneric())
     {
         conditionType = ConditionType.MakeGenericType(messageType);
     }
     handlerDef.DependencyByType(dependencyType, conditionType);
     return handlerDef;
 }
Beispiel #12
0
        protected override void configureObject(ObjectDef def)
        {
            var renderer       = def.DependencyByType(typeof(IViewRenderer), typeof(ViewRenderer));
            var viewDefinition = new ViewDefinition(createSparkDescriptor(true), createSparkDescriptor(false));

            var viewEntrySource =
                renderer.DependencyByType(typeof(IRenderAction), typeof(RenderAction))
                .DependencyByType(typeof(IViewFactory), typeof(ViewFactory))
                .DependencyByType(typeof(IViewEntrySource), typeof(ViewEntrySource));

            viewEntrySource.DependencyByValue(_cache);
            viewEntrySource.DependencyByValue(viewDefinition);
        }
Beispiel #13
0
        protected override ObjectDef toWriterDef()
        {
            var def = new ObjectDef(typeof(ViewWriter<>), ResourceType);

            def.DependencyByType<IViewFactory>(_token.ToViewFactoryObjectDef());

            var activator = new ObjectDef(typeof (FubuPageActivator<>), _token.ViewModel);
            activator.DependencyByValue(typeof (IViewToken), _token);

            def.Dependency(typeof (IFubuPageActivator), activator);

            return def;
        }
Beispiel #14
0
        protected override ObjectDef toWriterDef()
        {
            var def = new ObjectDef(typeof(ViewWriter <>), ResourceType);

            def.DependencyByType <IViewFactory>(_token.ToViewFactoryObjectDef());

            var activator = new ObjectDef(typeof(FubuPageActivator <>), _token.ViewModel);

            activator.DependencyByValue(typeof(IViewToken), _token);

            def.Dependency(typeof(IFubuPageActivator), activator);

            return(def);
        }
Beispiel #15
0
        private ObjectDef createTracerDef(ObjectDef objectDef)
        {
            var tracerDef = new ObjectDef(typeof(BehaviorTracer));

            tracerDef.DependencyByType <IActionBehavior>(objectDef);

            var chain = ParentChain();

            tracerDef.DependencyByValue(new BehaviorCorrelation
            {
                ChainId    = chain == null ? Guid.Empty : chain.UniqueId,
                BehaviorId = UniqueId
            });

            return(tracerDef);
        }
 private void attachNextBehavior(ObjectDef objectDef, DiagnosticLevel diagnosticLevel)
 {
     var nextObjectDef = Next.As<IContainerModel>().ToObjectDef(diagnosticLevel);
     objectDef.DependencyByType<IActionBehavior>(nextObjectDef);
 }
Beispiel #17
0
        private void attachNextBehavior(ObjectDef objectDef)
        {
            var nextObjectDef = Next.As <IContainerModel>().ToObjectDef();

            objectDef.DependencyByType <IActionBehavior>(nextObjectDef);
        }
Beispiel #18
0
        public SpecialView(IViewToken view)
        {
            _def = new ObjectDef(typeof(SpecialViewWriter <>), typeof(T));

            _def.DependencyByType <IViewFactory>(view.ToViewFactoryObjectDef());
        }
        private ObjectDef createTracerDef(ObjectDef objectDef)
        {
            var tracerDef = new ObjectDef(typeof(BehaviorTracer));
            tracerDef.DependencyByType<IActionBehavior>(objectDef);

            var chain = ParentChain();
            tracerDef.DependencyByValue(new BehaviorCorrelation
            {
                ChainId = chain == null ? Guid.Empty : chain.UniqueId,
                BehaviorId = UniqueId
            });

            return tracerDef;
        }