Ejemplo n.º 1
0
        private static ComponentRegistration <T> SetLifeStyle <T>(LifeStyleType lifeStyle, ComponentRegistration <T> registration) where T : class
        {
            if (lifeStyle == LifeStyleType.Singleton)
            {
                return(registration.LifestyleSingleton());
            }
            else if (lifeStyle == LifeStyleType.Transient)
            {
                return(registration.LifestyleTransient());
            }
            else if (lifeStyle == LifeStyleType.PerWebRequest)
            {
                return(registration.LifestylePerWebRequest());
            }
            else if (lifeStyle == LifeStyleType.PerThread)
            {
                return(registration.LifestylePerThread());
            }
            else if (lifeStyle == LifeStyleType.Scoped)
            {
                return(registration.LifestyleScoped());
            }

            return(registration);
        }
Ejemplo n.º 2
0
        private static object Resolve(Type type, TypeResolverContext context, LifeStyleType lifeStyleType)
        {
            MethodInfo method  = typeof(TypeResolver).GetMethod("ResolveWithLifeStyle");
            MethodInfo generic = method.MakeGenericMethod(type);

            return(generic.Invoke(null, new object[] { context, lifeStyleType }));
        }
Ejemplo n.º 3
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var coreComponents = new List <IIoCComponent>
            {
                new IoCComponent <IRetrieveJourneysPricingDomainService, JourneysPricingRetrieverDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IRetrieveServicePricingDomainService, ServicePricingRetrieverDomainService>
                {
                    Name          = "ServicePricingRetrieverDomainService",
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IRetrieveServicePricingDomainService, SeatsPricingRetrieverDomainService>
                {
                    Name          = "SeatsPricingRetrieverDomainService",
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IRetrieveBookingPricingDomainService, RetrieveBookingPricingDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                }
            };

            IoCContainer.Instance.Register(coreComponents);
        }
        public void Register <TInterface, TClass>(LifeStyleType lifeStyle = LifeStyleType.Transient)
            where TInterface : class
            where TClass : TInterface
        {
            if (TypeRegistry.Any(kvp => kvp.Key == typeof(TInterface)))
            {
                throw new ArgumentException("A concrete type for this interface has already been registered.");
            }

            TypeRegistry.Add(typeof(TInterface), new TypeRegistration(typeof(TInterface), typeof(TClass), lifeStyle));
        }
Ejemplo n.º 5
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var coreComponents = new List <IIoCComponent>
            {
                new IoCComponent <ICheckinPaxDomainService, CheckinPaxDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                }
            };

            IoCContainer.Instance.Register(coreComponents);
        }
Ejemplo n.º 6
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var components = new List <IIoCComponent>
            {
                new IoCComponent <IValidator <JourneyPriceRequest>, JourneyPriceRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                }
            };

            IoCContainer.Instance.Register(components);
        }
Ejemplo n.º 7
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var coreComponents = new List <IIoCComponent>
            {
                new IoCComponent <IAvailablePaymentMethodsDomainService, AvailablePaymentMethodsDomainService> {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IAddPaymentDomainService, AddCreditCardPaymentDomainService> {
                    LifeStyleType = defaultLifeStyleType, Name = "CreditCardPaymentAdder"
                }
            };

            IoCContainer.Instance.Register(coreComponents);
        }
Ejemplo n.º 8
0
        public void Register <T>(T instance, string key, LifeStyleType lifeStyle) where T : class
        {
            var registration = Component.For <T>().Instance(instance);

            registration = SetLifeStyle(lifeStyle, registration);

            if (!string.IsNullOrEmpty(key))
            {
                key = GetName <T>(key);
                registration.Named(key);
            }

            container.Register(registration);
        }
Ejemplo n.º 9
0
 public TypeRegistration(Type interfaceType, Type concreteType, LifeStyleType lifeStyle)
 {
     if (null == interfaceType)
     {
         throw new ArgumentNullException("interfaceType");
     }
     if (null == concreteType)
     {
         throw new ArgumentNullException("concreteType");
     }
     InterfaceType = interfaceType;
     ConcreteType  = concreteType;
     LifeStyle     = lifeStyle;
 }
Ejemplo n.º 10
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var coreComponents = new List <IIoCComponent>
            {
                new IoCComponent <ISaveBookingDomainService, SaveBookingDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IRetrieveBookingDomainService, RetrieveBookingDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IReloadBookingDomainService, ReloadBookingDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IGenerateEticketsDomainService, EticketsGeneratorDomainService>
                {
                    LifeStyleType = defaultLifeStyleType
                }
            };

            IoCContainer.Instance.Register(coreComponents);
        }
Ejemplo n.º 11
0
        public void Register <I, T>(LifeStyleType lifeStyle, string key, params KeyValuePair <string, object>[] arguments)
            where I : class
            where T : class, I
        {
            var registration = Component.For <I>().ImplementedBy <T>();

            if (arguments != null)
            {
                foreach (var arg in arguments)
                {
                    registration.DynamicParameters((kernel, parameters) => parameters[arg.Key] = arg.Value);
                }
            }

            registration = SetLifeStyle(lifeStyle, registration);

            if (!string.IsNullOrEmpty(key))
            {
                key = GetName <I>(key);
                registration.Named(key);
            }

            container.Register(registration);
        }
Ejemplo n.º 12
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var configurationTransport  = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/config/TransportsConfiguration.json");
            var transportsConfiguration = new JsonSerializer().Deserialize <ConfigTransports>(configurationTransport);

            if (transportsConfiguration?.Transports == null || !transportsConfiguration.Transports.Any())
            {
                throw new ConfigurationErrorsException("Invalid content for TransportsConfiguration.json file");
            }

            var coreComponents = new List <IIoCComponent>
            {
                new IoCComponent <IRetrieveSeatMapDomainService, RetrieveSeatMapDomainService>
                {
                    LifeStyleType = defaultLifeStyleType,
                    Dependencies  = new Dictionary <string, object>
                    {
                        { "transportsConfiguration", transportsConfiguration }
                    }
                }
            };

            IoCContainer.Instance.Register(coreComponents);
        }
Ejemplo n.º 13
0
 public Component(Type type, LifeStyleType lifeStyle)
 {
     ImplementationType = type;
     ImplementationLifestyle = lifeStyle;
 }
Ejemplo n.º 14
0
        public void Install(LifeStyleType defaultLifeStyleType)
        {
            var components = new List <IIoCComponent>
            {
                new IoCComponent <IValidator <Contact>, ContactValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <CreateBookingRequest>, CreateBookingRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <RetrieveBookingRequest>, RetrieveBookingRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <Booking>, BookingValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <Pax>, PaxValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <Payment>, PaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <CreditCardPayment>, CreditCardPaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <CreditPayment>, CreditPaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <LoyaltyPayment>, LoyaltyPaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <MobilePayment>, MobilePaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <PrePaidPayment>, PrePaidPaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <VoucherPayment>, VoucherPaymentValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <Journey>, JourneyValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <JourneyRequest>, JourneyRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <CheckinRequest>, CheckinRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <BoardingPassRequest>, BoardingPassRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <AddServiceRequest>, AddServiceRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType,
                },
                new IoCComponent <IValidator <SearchBookingRequest>, SearchBookingRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <AddBundleRequest>, AddBundleRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                },
                new IoCComponent <IValidator <AutoAssignSeatRequest>, AutoAssignSeatRequestValidator>
                {
                    LifeStyleType = defaultLifeStyleType
                }
            };

            IoCContainer.Instance.Register(components);
        }
Ejemplo n.º 15
0
 public IServiceContainer Register <TService, TImpl>(LifeStyleType lifeStyle) where TService : class where TImpl : class, TService
 {
     Container.Register <TService, TImpl>(LifeStyle(lifeStyle));
     return(this);
 }
Ejemplo n.º 16
0
        public static TInterface ResolveWithLifeStyle <TInterface>(TypeResolverContext context, LifeStyleType lifeStyleType)
        {
            ILifeStyle lifeStyle = _lifeStyles.FirstOrDefault(ls => ls.Type == lifeStyleType);

            if (null == lifeStyle)
            {
                throw new InvalidOperationException("Unknown lifestyle type");
            }

            return(lifeStyle.Resolve <TInterface>(context));
        }
Ejemplo n.º 17
0
 public void Register <I, T>(LifeStyleType lifeStyle)
     where I : class
     where T : class, I
 {
     Register <I, T>(lifeStyle, string.Empty);
 }
Ejemplo n.º 18
0
 public void Register <T>(T instance, LifeStyleType lifeStyle) where T : class
 {
     Register(instance, string.Empty, lifeStyle);
 }