Ejemplo n.º 1
0
        private static void Run(ApplicationInstance applicationInstance)
        {
            Module experimentalModule = applicationInstance.FindModule("DomainLayer", "ExperimentalModule");

            TransientBuilder <Customer> customerBuilder = experimentalModule.TransientBuilderFactory.NewTransientBuilder <Customer>();
            ValueBuilder <Address>      addressBuilder  = experimentalModule.ValueBuilderFactory.NewValueBuilder <Address>();

            Address protoAddress = addressBuilder.Prototype();

            protoAddress.City       = "Foo City";
            protoAddress.StreetName = "Acme road 123";
            protoAddress.ZipCode    = "888-555";

            var protoCustomer = customerBuilder.PrototypeFor <Customer>();

            protoCustomer.Name    = "Acme Inc";
            protoCustomer.Email   = "*****@*****.**";
            protoCustomer.Address = addressBuilder.NewInstance();

            Customer customer = customerBuilder.NewInstance();

            customer.Print();

            customer.SayHello();

            //customer.Address.City = "abc"; //should throw, immutable object

            Address otherAddress = addressBuilder.NewInstance();

            bool areEqual = customer.Address.Equals(otherAddress);

            if (areEqual)
            {
                Console.WriteLine("customer.Address and otherAddress are equal");
            }

            //customer.SayHelloTo(null); //should throw, name is not optional

            CustomerRepository customerRepo = experimentalModule
                                              .ServiceFinder
                                              .FindService <CustomerRepository>()
                                              .Get();

            var id = customerRepo as Identity;

            Console.WriteLine(id.Identity);

            Customer x = customerRepo.NewCustomer("arne");

            customer.SayHelloTo("Roger");

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public T NewValue <T>()
        {
            ValueBuilder <T> builder = this.GetBuilder <T>(typeof(T));

            return(builder.NewInstance());
        }