public static IApplicationContext GetFluentConfigurator(string BusinessEntityAssembly, string BusinessManagementAssembly, string ConnectionString)
        {
            var ctx = new FluentApplicationContext();

            //Configurando os parâmetros
            ctx.RegisterDefault<RepositoryParameter>()

                .BindProperty(x => x.AuditoryEnabled).ToValue(false)

                .BindProperty(x => x.ConnectionString)
                .ToValue(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)

                .BindProperty(x => x.DomainMap).ToValue(BusinessEntityAssembly)
                .BindProperty(x => x.GenerateSchema).ToValue(true)
                .BindProperty(x => x.ORMUtilizado).ToValue(ORM.NHibernate).GetReference();

               //Registrando a Sessão
            ctx.RegisterDefault<ConfigurationAutoMapper>()
                    .BindProperty(x => x.Parameters).ToRegisteredDefaultOf<RepositoryParameter>();

            ctx.RegisterDefault<SessionFactorySqlServer2008NHibernate>()
                .BindProperty(x => x.Config)
                .ToRegisteredDefaultOf<ConfigurationAutoMapper>()
                .GetReference();

            //Criando estrutura genérica para atender o requisito acima.
            //here
            var assBm = Assembly.Load(BusinessManagementAssembly);
            var assBe = Assembly.Load(BusinessEntityAssembly);

            foreach (var bm in assBm.ExportedTypes)
            {

                var be = assBe.ExportedTypes.FirstOrDefault(x => x.Name.Equals(bm.Name.Substring(0, bm.Name.Length - 2)));

                var model = Activator.CreateInstance(typeof(RepositoryBaseNHibernate<>).MakeGenericType(be));

                var registDefault = ctx.GetType().GetMethod("RegisterDefault").MakeGenericMethod(model.GetType()).Invoke(ctx, null);

                var obj = registDefault.GetType()
                        .GetMethod("BindPropertyNamed")
                        .MakeGenericMethod(typeof (SessionFactorySqlServer2008NHibernate))
                        .Invoke(registDefault, new[] { "SessionFactory" });

                obj.GetType().GetMethod("ToRegisteredDefault").Invoke(obj, null);

                var regdefault = ctx.GetType().GetMethod("RegisterDefault").MakeGenericMethod(bm).Invoke(ctx,null);

                var buildPrperty =
                    regdefault.GetType()
                        .GetMethod("BindPropertyNamed")
                        .MakeGenericMethod(model.GetType())
                        .Invoke(regdefault, new[] {"Repository"});

                buildPrperty.GetType().GetMethod("ToRegisteredDefault").Invoke(buildPrperty, null);
            }
            //here

            return ctx;
        }
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<Endpoint>();

			ctx.RegisterDefault<DisplayCommand>()
				.AsPrototype(); //every request for DisplayCommand should return new instance

			ctx.RegisterDefault<RepeatingInterceptor>();
			ctx.RegisterDefault<DelayingInterceptor>()
				.BindConstructorArg<int>().ToValue(3000);

			ctx.RegisterDefaultProxyFactory<ICommand>()
				.TargetingDefault<DisplayCommand>()
				.ReturningPrototypes() //every request for ICommand should return new instance of proxy (comment it and type few lines during program run to see change)
				.InterceptedByDefault<DelayingInterceptor>()
				.InterceptedByDefault<RepeatingInterceptor>(); //Repeating interceptor is called after DelyingInterceptor, so there would be no delays between repeats

			ctx.RegisterDefault<Sender>()
				.DependingOnDefault<Consumer>()
				.Autowire(); //autowiring endpoint dependency

			ctx.RegisterDefault<Consumer>()
				.BindLookupMethodNamed<ICommand>("GetCommand").ToRegisteredDefault() //method is protected so it is not possible to use lambda to get it
				.Autowire() //autowiring endpoint dependency				
				.CallOnInit(c => c.Start());

			return ctx;
		}
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			var painterRef = ctx.RegisterDefault<Painter>().GetReference();

			ctx.RegisterNamed<Polisher>("polisher");

			ctx.RegisterDefault<Distributor>()
				.BindProperty(d => d.DistributionMap).ToDictionary(dict =>
				{
					dict[Def.Value("Motorcycle")] = Def.Reference<Shop>();
					dict[Def.Value("Car")] = Def.Reference<Shop>();
					dict[Def.Value("Luxury Car")] = Def.Object<Shop>(s => s.BindConstructorArg<string>().ToValue("Luxury Store that nobody knows."));
				});

			ctx.RegisterDefault<Shop>()
				.UseConstructor<string>(name => new Shop(name))
				.BindConstructorArg().ToValue("Local store");

			ctx.RegisterDefault<Factory>()
				.UseConstructor<IWorker[]>(workers => new Factory(workers))
				.BindConstructorArg()
				.ToArray(
					Def.Object<Constructor>(),
					painterRef,
					Def.Reference<Polisher>("polisher"),
					Def.Reference<Distributor>()
				);

			return ctx;
		}
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<Pig>()
				.AsPrototype() //every request will return a new instance of Pig
				.BindConstructorArg<string>().ToValue("Small Piggy");

			ctx.RegisterDefault<Cow>()
				.AsPrototype();

			ctx.RegisterDefault<Barn>()
				.AsPrototype();

			ctx.RegisterDefault<Pigsty>()
				.AsSingleton(); //The Pigsty is registered as singleton, so every request returns the same instance (what is visible on second RunFarm())

			ctx.RegisterNamed<Farm>("pigFarm")
				.BindLookupMethod(f => f.CreateAnimal()).ToRegisteredDefaultOf<Pig>()
				.BindLookupMethod(f => f.CreateShelter()).ToRegisteredDefaultOf<Pigsty>();

			ctx.RegisterNamed<Farm>("cowFarm")
				.BindLookupMethod(f => f.CreateAnimal()).ToRegisteredDefaultOf<Cow>()
				.BindLookupMethod(f => f.CreateShelter()).ToRegisteredDefaultOf<Barn>();

			return ctx;
		}
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<Calculator>();
			ctx.RegisterDefault<DisplayingInterceptor>();

			ctx.RegisterDefaultProxyFactory<ICalculator>()
				.TargetingDefault<Calculator>()
				.InterceptedByDefault<DisplayingInterceptor>();

			return ctx;
		}
        public void Then_the_entries_must_be_added()
        {
            FluentApplicationContext.Register <MappedPropertyResolver <string> >("mappedProperty")
            .Bind(x => x.MapKey).To("KEY")
            .Bind <string>("['DEV']").To("DEV_VALUE")
            .Bind <string>("['KEY']").To("KEY_VALUE");

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var propertyResolver = applicationContext.GetObject("mappedProperty");

            Assert.AreEqual("KEY_VALUE", propertyResolver);
        }
Exemple #7
0
        public void Then_the_object_must_registered_with_the_identifier_passed_in()
        {
            const string identifier = "myobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.AStringProperty).To("somevalue");

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            bool definitionPresent = applicationContext.ContainsObjectDefinition(identifier);

            Assert.IsTrue(definitionPresent);
        }
Exemple #8
0
        public void Then_it_must_return_the_singleton_instance()
        {
            const string identifierA = "myobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifierA);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var objectA = applicationContext.GetObject <ObjectWithProperties>(identifierA);
            var objectB = applicationContext.GetObject <ObjectWithProperties>(identifierA);

            Assert.AreSame(objectB, objectA);
        }
Exemple #9
0
        public void Then_the_object_must_be_initialised_with_the_right_values_when_passed_by_index()
        {
            FluentApplicationContext.Register<ObjectWithConstructor>("object")
                .BindConstructorArgumentAtIndex<string>(0).To("value")
                .BindConstructorArgumentAtIndex<int>(1).To(1);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithConstructor) applicationContext.GetObject("object");

            Assert.AreEqual("value", initialisedObject.First);
            Assert.AreEqual(1, initialisedObject.Second);
        }
Exemple #10
0
        protected override IApplicationContext CreateContext()
        {
            var ctx = new FluentApplicationContext();

            ctx.RegisterDefault <Calculator>();
            ctx.RegisterDefault <DisplayingInterceptor>();

            ctx.RegisterDefaultProxyFactory <ICalculator>()
            .TargetingDefault <Calculator>()
            .InterceptedByDefault <DisplayingInterceptor>();

            return(ctx);
        }
        public void Then_the_sub_property_shouldnt_be_initialised_if_no_parent_selected()
        {
            FluentApplicationContext.Register <TestObject>()
            .Bind(x => x.PropertyX).To("mysubvalue");

            FluentApplicationContext.Register <DerivedObject>()
            .Bind(x => x.SomeProperty).To("derived");

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            var testObject = context.GetObject <DerivedObject>();

            Assert.AreNotEqual("mysubvalue", testObject.PropertyX);
        }
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<Cat>()
				.BindConstructorArg<string>().ToValue("Kitty");

			ctx.RegisterDefault<PersonWithCat>()
				.UseConstructor((string name, Cat cat) => new PersonWithCat(name, cat))
				.BindConstructorArg().ToValue("Josephine") //binds string type argument to constant value
				.BindConstructorArg().ToRegisteredDefault(); //binds Cat type argument to registered Cat instance

			return ctx;
		}
Exemple #13
0
        public void Then_the_constructor_argument_of_interface_type_can_be_bound_to_its_implementation()
        {
            FluentApplicationContext.Register<ObjectWithProperties>();

            FluentApplicationContext.Register<ObjectWithConstructor>("object")
                .BindConstructorArgument<IObjectWithPropertiesInterface>().To<ObjectWithProperties>();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = applicationContext.GetObject<ObjectWithConstructor>("object");
            var objectInjected = applicationContext.GetObject<ObjectWithProperties>();

            Assert.AreSame(objectInjected, initialisedObject.ObjectInferface);
        }
Exemple #14
0
        public void Then_the_object_must_be_initialised_with_the_right_values_when_passed_by_name_and_reference()
        {
            FluentApplicationContext.Register<TestObject>()
                .Bind(t => t.PropertyX).To("somevalue");

            FluentApplicationContext.Register<ObjectWithConstructor>("object")
                .BindConstructorArgument<TestObject>().To<TestObject>();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithConstructor) applicationContext.GetObject("object");

            Assert.AreEqual("somevalue", initialisedObject.TestObject.PropertyX);
        }
Exemple #15
0
        public void Then_the_object_must_not_be_the_same_if_not_registered_as_a_singleton()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()))
            .AsNonSingleton();

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectA = context.GetObject <ObjectWithConstructor>();
            ObjectWithConstructor objectB = context.GetObject <ObjectWithConstructor>();

            Assert.AreNotSame(objectA, objectB);
        }
        public void Then_I_should_be_able_to_register_several_objects_to_the_same_interface()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register <AnotherObjectWithSameInterface>();

            FluentApplicationContext.Bind <IObjectWithPropertiesInterface>().To <ObjectWithProperties>().When(() => true);
            FluentApplicationContext.Bind <IObjectWithPropertiesInterface>().To <AnotherObjectWithSameInterface>().When(() => false);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var objectInstance = applicationContext.GetObject <IObjectWithPropertiesInterface>();

            Assert.IsNotNull(objectInstance);
        }
Exemple #17
0
        protected override IApplicationContext CreateContext()
        {
            var ctx = new FluentApplicationContext();

            ctx.RegisterDefault <Cat>()
            .BindConstructorArg <string>().ToValue("Kitty");

            ctx.RegisterDefault <PersonWithCat>()
            .UseConstructor((string name, Cat cat) => new PersonWithCat(name, cat))
            .BindConstructorArg().ToValue("Josephine")                     //binds string type argument to constant value
            .BindConstructorArg().ToRegisteredDefault();                   //binds Cat type argument to registered Cat instance

            return(ctx);
        }
        public void Then_it_should_only_return_the_registered_object_which_is_available_by_condition()
        {
            FluentApplicationContext.Register <ObjectWithProperties>().Bind(o => o.AStringProperty).To("validobject");
            FluentApplicationContext.Register <AnotherObjectWithSameInterface>().Bind(o => o.AStringProperty).To("invalidobject");

            FluentApplicationContext.Bind <IObjectWithPropertiesInterface>().To <ObjectWithProperties>().When(() => true);
            FluentApplicationContext.Bind <IObjectWithPropertiesInterface>().To <AnotherObjectWithSameInterface>().When(() => false);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var objectInstance = applicationContext.GetObject <IObjectWithPropertiesInterface>();

            Assert.AreEqual("validobject", objectInstance.AStringProperty);
        }
        public void Then_the_object_string_property_must_be_set_to_its_bound_value()
        {
            const string identifier    = "myobjectname";
            const string propertyValue = "someValue";

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.AStringProperty).To(propertyValue);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);

            Assert.AreEqual(propertyValue, initialisedObject.AStringProperty);
        }
        public void Then_the_list_can_contain_inline_definition()
        {
            FluentApplicationContext.Register <TestObject>()
            .Bind(x => x.ListOfTestObjects).ToDefinition(
                Inline.List <TestObject>()
                .AddDefinition(Inline.Object <TestObject>().Bind(x => x.PropertyX).To("blah"))
                );

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            var testObject = context.GetObject <TestObject>();

            Assert.IsNotNull(testObject.ListOfTestObjects);
            Assert.AreEqual("blah", testObject.ListOfTestObjects[0].PropertyX);
        }
Exemple #21
0
        public void Then_the_object_of_same_type_with_different_identifiers_must_not_be_the_same()
        {
            const string identifierA = "myobjectname";
            const string identifierB = "mysecondobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifierA);
            FluentApplicationContext.Register <ObjectWithProperties>(identifierB);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var objectA = applicationContext.GetObject <ObjectWithProperties>(identifierA);
            var objectB = applicationContext.GetObject <ObjectWithProperties>(identifierB);

            Assert.AreNotSame(objectA, objectB);
        }
Exemple #22
0
        public void Then_the_object_must_be_instantiated_with_the_context_injected_values()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()));

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectWithConstructor = context.GetObject <ObjectWithConstructor>();
            ObjectWithProperties  childObject           = context.GetObject <ObjectWithProperties>();

            Assert.IsNotNull(objectWithConstructor);
            Assert.IsNotNull(objectWithConstructor.ObjectInferface);
            Assert.AreSame(childObject, objectWithConstructor.ObjectInferface);
        }
        public void Then_the_sub_properties_must_be_initialised()
        {
            FluentApplicationContext.Register <TestObject>()
            .Bind(x => x.PropertyX).To("mysubvalue");

            FluentApplicationContext.Register <DerivedObject>()
            .WithParentDefinition <TestObject>()
            .Bind(x => x.SomeProperty).To("derived");

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            var testObject = context.GetObject <DerivedObject>();

            Assert.AreEqual("mysubvalue", testObject.PropertyX);
        }
Exemple #24
0
        public void Then_the_object_property_binding_must_also_be_injected()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register(c => new TestObject
            {
                SomeObject = c.GetObject <ObjectWithProperties>()
            });


            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            TestObject testObject = context.GetObject <TestObject>();

            Assert.IsNotNull(testObject.SomeObject);
        }
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<Person>()
				.BindProperty(p => p.Name).ToValue("John") //binds Person.Name to constant value
				.BindProperty(p => p.Address).ToRegisteredDefault(); //binds Person.Address to other object registered in context

			ctx.RegisterDefault<Address>()
				.BindProperty(a => a.City).ToValue("London")
				.BindProperty(a => a.PostCode).ToValue("AB1 12CD")
				.BindProperty(a => a.Street).ToValue("Some Street");

			return ctx;
		}
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();

			ctx.RegisterDefault<ArithmenticMeanCalculator>();

			ctx.RegisterDefault<CreditsCalculator>()
				.BindConstructorArg<double>().ToValue(2.5)
				//the line below instruct Spring to override GetMeanCalculator() method with one returning ArithmeticMeanCalculator instance registered above
				.BindLookupMethod(c => c.GetMeanCalculator()).ToRegisteredDefaultOf<ArithmenticMeanCalculator>();

			ctx.RegisterDefaultAlias<ICreditsCalculator>().ToRegisteredDefault<CreditsCalculator>();

			return ctx;
		}
Exemple #27
0
        protected override IApplicationContext CreateContext()
        {
            var ctx = new FluentApplicationContext();

            ctx.RegisterDefault <ArithmenticMeanCalculator>();

            ctx.RegisterDefault <CreditsCalculator>()
            .BindConstructorArg <double>().ToValue(2.5)
            //the line below instruct Spring to override GetMeanCalculator() method with one returning ArithmeticMeanCalculator instance registered above
            .BindLookupMethod(c => c.GetMeanCalculator()).ToRegisteredDefaultOf <ArithmenticMeanCalculator>();

            ctx.RegisterDefaultAlias <ICreditsCalculator>().ToRegisteredDefault <CreditsCalculator>();

            return(ctx);
        }
Exemple #28
0
        protected override IApplicationContext CreateContext()
        {
            var ctx = new FluentApplicationContext();

            ctx.RegisterDefault <Person>()
            .BindProperty(p => p.Name).ToValue("John")                     //binds Person.Name to constant value
            .BindProperty(p => p.Address).ToRegisteredDefault();           //binds Person.Address to other object registered in context

            ctx.RegisterDefault <Address>()
            .BindProperty(a => a.City).ToValue("London")
            .BindProperty(a => a.PostCode).ToValue("AB1 12CD")
            .BindProperty(a => a.Street).ToValue("Some Street");

            return(ctx);
        }
Exemple #29
0
        public void Then_the_dictionary_must_be_injected()
        {
            const string identifier = "myobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.ADictionaryProperty).ToDefinition(
                Inline.Dictionary <string, string>()
                .AddEntry().WithKey("myvalue").AndValue("somevalue"));

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);

            Assert.IsTrue(initialisedObject.ADictionaryProperty.ContainsKey("myvalue"));
            Assert.AreEqual("somevalue", initialisedObject.ADictionaryProperty["myvalue"]);
        }
Exemple #30
0
        public void Then_the_object_of_same_type_with_different_identifiers_must_be_registered()
        {
            const string identifierA = "myobjectname";
            const string identifierB = "mysecondobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifierA);
            FluentApplicationContext.Register <ObjectWithProperties>(identifierB);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            bool definitionAPresent = applicationContext.ContainsObjectDefinition(identifierA);
            bool definitionBPresent = applicationContext.ContainsObjectDefinition(identifierB);

            Assert.IsTrue(definitionAPresent);
            Assert.IsTrue(definitionBPresent);
        }
        public void Then_the_convention_is_not_applied_to_types_which_are_not_in_lookup()
        {
            FluentApplicationContext.RegisterConvention()
            .For(() => AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.Contains("AnotherTestLibrary")).SelectMany(a => a.GetTypes()).ToList())
            .Apply <PropertyTypeInjectionConvention>()
            .Inject <IObjectWithPropertiesInterface>().With <ObjectWithProperties>();

            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register <TestObject>();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            TestObject objectProperties = applicationContext.GetObject <TestObject>();

            Assert.IsNull(objectProperties.SomeObject);
        }
Exemple #32
0
        public void Then_it_should_still_be_there_when_the_context_is_refreshed()
        {
            const string identifierA = "myobjectname";

            FluentApplicationContext.Register <ObjectWithProperties>(identifierA).AsNonSingleton();

            _applicationContextContainer.InitialiseContext();

            _applicationContextContainer.SetDirty();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var objectA = applicationContext.GetObject <ObjectWithProperties>(identifierA);

            Assert.IsNotNull(objectA);
        }
        public void Then_the_properties_of_type_defined_in_convention_must_be_injected()
        {
            FluentApplicationContext.RegisterConvention()
            .For(() => AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.Contains("FluentSpring.Tests")).SelectMany(a => a.GetTypes()).ToList())
            .Apply <PropertyTypeInjectionConvention>()
            .Inject <IObjectWithPropertiesInterface>().With <ObjectWithProperties>();

            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register <TestObject>();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            TestObject objectProperties = applicationContext.GetObject <TestObject>();

            Assert.IsNotNull(objectProperties.SomeObject);
        }
Exemple #34
0
        public void Then_the_property_must_be_initialised_by_its_registered_reference()
        {
            const string identifier = "myobjectname";

            FluentApplicationContext.Register <TestObject>().Bind(t => t.PropertyX).To("somevalue");

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.TestObject).To <TestObject>();

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);
            var testObject        = (TestObject)applicationContext.GetObject(typeof(TestObject).FullName);

            Assert.AreSame(testObject, initialisedObject.TestObject);
        }
        public void Then_the_list_must_be_initialised()
        {
            FluentApplicationContext.Register <TestObject>()
            .Bind(x => x.ListOfString).ToDefinition(
                Inline.List <string>()
                .Add("first")
                .Add("second")
                );

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            var testObject = context.GetObject <TestObject>();

            Assert.IsNotNull(testObject.ListOfString);
            Assert.Contains("first", (ICollection)testObject.ListOfString);
            Assert.Contains("second", (ICollection)testObject.ListOfString);
        }
Exemple #36
0
        public void Then_the_object_must_be_retrievable_by_name_with_the_context_injected_values()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();

            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()), "objectA");
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor("somestring"), "objectB");

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectA = context.GetObject <ObjectWithConstructor>("objectA");
            ObjectWithConstructor objectB = context.GetObject <ObjectWithConstructor>("objectB");

            Assert.IsNotNull(objectA.ObjectInferface);
            Assert.AreEqual("somestring", objectB.First);
        }
        public void Then_the_object_property_must_be_initialised()
        {
            const string identifier  = "myobjectname";
            const string myTestValue = "mytestvalue";

            FluentApplicationContext.Register <TestObject>().Bind(t => t.PropertyX).To("somevalue");

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.TestObject)
            .ToDefinition(Inline.Object <TestObject>()
                          .Bind(t => t.PropertyX).To(myTestValue));

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);

            Assert.AreEqual(myTestValue, initialisedObject.TestObject.PropertyX);
        }
        public void Then_object_dictionary_property_must_be_set_to_its_bound_value()
        {
            const string identifier = "myobjectname";
            IDictionary <string, string> propertyValue = new Dictionary <string, string>();

            propertyValue.Add("key", "value");

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.ADictionaryProperty).To(propertyValue);

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);

            Assert.AreSame(propertyValue, initialisedObject.ADictionaryProperty);
            Assert.IsTrue(initialisedObject.ADictionaryProperty.ContainsKey("key"));
            Assert.AreEqual("value", initialisedObject.ADictionaryProperty["key"]);
        }
		protected override IApplicationContext CreateContext()
		{
			FluentApplicationContext ctx = new FluentApplicationContext();

			ctx.RegisterDefault<BobEngineer>();

			//the factories are registered with ids to allow having multiple instances of same class in context
			ctx.RegisterNamed<Factory>("standardFactory") 
				.BindProperty(f => f.Engineer).ToRegisteredDefaultOf<BobEngineer>()
				.BindProperty(f => f.Description).ToValue("Standard Factory");

			ctx.RegisterDefault<RobotEngineer>();

			ctx.RegisterNamed<Factory>("roboticFactory")
				.BindProperty(f => f.Engineer).ToRegisteredDefaultOf<RobotEngineer>()
				.BindProperty(f => f.Description).ToValue("Robotic Super Factory");

			return ctx;
		}
		protected override IApplicationContext CreateContext()
		{
			var ctx = new FluentApplicationContext();
			ctx.RegisterDefault<ButtonFactory>().UseStaticFactoryMethod(ButtonFactory.CreateInstance);

			var closeBt = ctx.RegisterUniquelyNamed<Button>()
				.UseFactoryMethod<ButtonFactory>(f => f.CreateButton()).OfRegisteredDefault()
				.BindProperty(b => b.Name).ToValue("Close")
				.GetReference();

			var saveBt = ctx.RegisterUniquelyNamed<Button>()
				.UseFactoryMethod<ButtonFactory>(f => f.CreateButton()).OfRegisteredDefault()
				.BindProperty(b => b.Name).ToValue("Save")
				.GetReference();

			ctx.RegisterDefault<Window>()
				.BindProperty(w => w.CloseButton).ToRegistered(closeBt)
				.BindProperty(w => w.SaveButton).ToRegistered(saveBt);

			ctx.RegisterDefaultAlias<IWindow>().ToRegisteredDefault<Window>();

			return ctx;
		}
		public void SetUp()
		{
			_ctx = new FluentApplicationContext();
			CountingType.ClearCounter();
		}
		public void SetUp()
		{
			_ctx = new FluentApplicationContext();
		}