コード例 #1
0
ファイル: Curry_Specs.cs プロジェクト: phatboyg/ServiceBook
        public void Should_narrow_the_factory_width()
        {
            var factory = new ConstructorFactory<MyClass, MyDependency>(x => new MyClass(x));
            var dependencyFactory = new ConstructorFactory<MyDependency>(() => new MyDependency());
            var curryFactory = new PartialFactory<MyClass, MyDependency>(factory, dependencyFactory);
            MyClass subject = curryFactory.Get();

            Assert.IsNotNull(subject);
            Assert.IsNotNull(subject.Dependency);
        }
        public ParentObject Get()
        {
            if (_factory == null)
            {
                var other = new ConstructorFactory<DependentObject>(() => new DependentObject());
                var factory1 = new ConstructorFactory<ParentObject, DependentObject>(x => new ParentObject(x));
                _factory = new PartialFactory<ParentObject, DependentObject>(factory1, other);
            }
            var factory = (ServiceBook.Factory<ParentObject>)_factory;

            return factory.Get();
        }