public IConstructor ProvideConstructor(IService service) { if (service.Flags.HasFlag(ServiceFlagConstants.ServiceCtor)) { ServiceFlag flag = service.Flags.GetFlag(ServiceFlagConstants.ServiceCtor); IMember memberParent = flag.Member; if (ConstructorChecker.Check(memberParent)) { return(ConstructorGenerator.GenerateConstructor((ConstructorInfo)memberParent.Instance)); } } return(DefaultConstructorProvider.ProvideDefaultConstructor(service)); }
public ServiceFlags ProvideFlags(Type type) { ServiceFlags flags = ServiceFlags.CreateNew(); IEnumerable <ServiceFlagAttribute> flagAttributes = AttributesFinder.FindAttributesEverywhere(type, (member, attr) => { ServiceFlagAttribute flagAttr = (ServiceFlagAttribute)attr; ServiceFlag sflag = flagAttr.ServiceFlag; return(new ServiceFlagAttribute() { ServiceFlag = new ServiceFlag(sflag.Name, sflag.Value) { Member = MemberGenerator.GenerateMember(member) } }); }); foreach (ServiceFlagAttribute attribute in flagAttributes) { flags.AddFlag(attribute.ServiceFlag.Name, attribute.ServiceFlag.Value, attribute.ServiceFlag.Member); } return(flags); }
public ServiceFlagAttribute(string name, object value = null) { ServiceFlag = new ServiceFlag(name, value); }
public IEnumerable <ServiceRegistrationFlag> GenerateFlags(ServiceFlags flags, Type type, object instance, IConstructorParameters constructorParameters) { if (instance != null) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.HasInstance, instance)); } if (constructorParameters != null) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.HasConstructorParameters, true)); yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.ConstructorParameters, constructorParameters)); } Type baseType = BaseTypeFinder.GetBaseTypeAnotherOf(type, null, typeof(object)); if (baseType != null) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.AsClass, baseType)); } IEnumerable <IInterface> interfaces = InterfacesGenerator.GenerateInterfaces(flags, type); foreach (IInterface @interface in interfaces) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.AsInterface, @interface)); } ConstructorInfo[] constructors = ConstructorInfoListGenerator.GenerateList(type); if (flags.HasFlag(ServiceFlagConstants.ServiceCtor)) { ServiceFlag flag = flags.GetFlag(ServiceFlagConstants.ServiceCtor); IMember member = flag.Member; IConstructor serviceConstructor = ConstructorGenerator.GenerateConstructor((ConstructorInfo)member.Instance); yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.DefaultConstructor, serviceConstructor)); } else { ConstructorInfo defaultConstructorInfo = DefaultConstructorInfoProvider.ProvideDefaultConstructor(constructors); IConstructor defaultConstructor = ConstructorGenerator.GenerateConstructor(defaultConstructorInfo); if (defaultConstructor != null) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.DefaultConstructor, defaultConstructor)); } } foreach (ConstructorInfo constructor in constructors) { IConstructor ctor = ConstructorGenerator.GenerateConstructor(constructor); yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.Constructor, ctor)); } Type[] genericArguments = type.GetGenericArguments(); if (genericArguments.Any()) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.HasGenericParameters, null)); yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.GenericParameters, genericArguments)); } foreach (ServiceFlag factoryFlag in flags.GetFlags(ServiceFlagConstants.ServiceFactory)) { yield return(new ServiceRegistrationFlag(RegistrationFlagConstants.Factory, null) { Member = factoryFlag.Member }); } }
public ServiceBuilder AddFlag(ServiceFlag flag) { return(Update(x => x.Flags.Add(flag))); }