public PropertyMapper(ITypeMapCollection mixinsMap) { var mapped = mixinsMap.Select(mixin => new { ServiceType = mixin.ServiceType, ConcreteType = mixin.ConcreteType, ContractProperties = mixin.ServiceType.GetProperties(), PropertiesImpl = mixin.ConcreteType.GetProperties().ToSet() }); var mappedPropertiesEnumerable = mapped.SelectMany(map => { var properties = map.ContractProperties; return(properties.Select(property => { var match = property.SelectFirst(map.PropertiesImpl, (c, impl) => c.IsMatchedTo(impl), (c, impl) => new { ServiceProperty = c, ConcreteProperty = impl }); return new PropertyMap(map.ServiceType, map.ConcreteType, match.ServiceProperty, match.ConcreteProperty); })); }); mappedProperties = mappedPropertiesEnumerable.ToListOf <IPropertyMap>(); }
public MethodMapper(ITypeMapCollection typeMap) { Func<MethodInfo, bool> methodPredicate = methodInfo => !methodInfo.IsSpecialName; var mapped = typeMap.Select(map => new { ContractType = map.ServiceType, ImplementationType = map.ConcreteType, ContractMethods = map.ServiceType.GetPublicMethods().Where(methodPredicate), MethodsImpl = map.ConcreteType.GetPublicMethods().ToSet(methodPredicate), }); var mappedMethodsEnumerable = mapped.SelectMany(map => { var methods = map.ContractMethods; return methods.Select(method => { var match = method.SelectFirst(map.MethodsImpl, (c, impl) => c.IsMatchedTo(impl), (c, impl) => new { MethodImpl = impl, ContractMethod = c }); return new MethodMap(map.ContractType, map.ImplementationType, match.ContractMethod, match.MethodImpl); }); }); mappedMethods = mappedMethodsEnumerable.ToListOf<IMethodMap>(); }
public PropertyMapper(ITypeMapCollection mixinsMap) { var mapped = mixinsMap.Select(mixin => new { ServiceType = mixin.ServiceType, ConcreteType = mixin.ConcreteType, ContractProperties = mixin.ServiceType.GetProperties(), PropertiesImpl = mixin.ConcreteType.GetProperties().ToSet() }); var mappedPropertiesEnumerable = mapped.SelectMany(map => { var properties = map.ContractProperties; return properties.Select(property => { var match = property.SelectFirst(map.PropertiesImpl, (c, impl) => c.IsMatchedTo(impl), (c, impl) => new { ServiceProperty = c, ConcreteProperty = impl }); return new PropertyMap(map.ServiceType, map.ConcreteType, match.ServiceProperty, match.ConcreteProperty); }); }); mappedProperties = mappedPropertiesEnumerable.ToListOf<IPropertyMap>(); }
public MixinsWeaverStrategy(ITypeDefinition typeDefinition, ITypeMapCollection mixinsMap, IEnumerable <IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry) { this.registry = registry; this.mixinsMap = mixinsMap; this.methodWeavers = methodWeavers; this.typeDefinition = typeDefinition; }
public EventMapper(ITypeMapCollection typeMap) { Func<EventInfo, bool> eventPredicate = eventdInfo => !eventdInfo.IsSpecialName; var mapped = typeMap.Select(map => new { ContractType = map.ServiceType, ImplementationType = map.ConcreteType, ContractEvents = map.ServiceType.GetPublicEvents().Where(eventPredicate), EventsImpl = map.ConcreteType.GetPublicEvents().ToSet(eventPredicate), }); var mappedEventsEnumerable = mapped.SelectMany(map => { var events = map.ContractEvents; return events.Select(@event => { var match = @event.SelectFirst(map.EventsImpl, (c, impl) => c.GetAddMethod().IsMatchedTo(impl.GetAddMethod()), (c, impl) => new { EventImpl = impl, ContractEvent = c }); return new EventMap(map.ContractType, map.ImplementationType, match.ContractEvent, match.EventImpl); }); }); mappedEvents = mappedEventsEnumerable.ToListOf<IEventMap>(); }
public MixinsWeaverStrategy(ITypeDefinition typeDefinition, ITypeMapCollection mixinsMap, IEnumerable<IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry) { this.registry = registry; this.mixinsMap = mixinsMap; this.methodWeavers = methodWeavers; this.typeDefinition = typeDefinition; }
public MethodMapper(ITypeMapCollection typeMap) { Func <MethodInfo, bool> methodPredicate = methodInfo => !methodInfo.IsSpecialName; var mapped = typeMap.Select(map => new { ContractType = map.ServiceType, ImplementationType = map.ConcreteType, ContractMethods = map.ServiceType.GetPublicMethods().Where(methodPredicate), MethodsImpl = map.ConcreteType.GetPublicMethods().ToSet(methodPredicate), }); var mappedMethodsEnumerable = mapped.SelectMany(map => { var methods = map.ContractMethods; return(methods.Select(method => { var match = method.SelectFirst(map.MethodsImpl, (c, impl) => c.IsMatchedTo(impl), (c, impl) => new { MethodImpl = impl, ContractMethod = c }); return new MethodMap(map.ContractType, map.ImplementationType, match.ContractMethod, match.MethodImpl); })); }); mappedMethods = mappedMethodsEnumerable.ToListOf <IMethodMap>(); }
public EventMapper(ITypeMapCollection typeMap) { Func <EventInfo, bool> eventPredicate = eventdInfo => !eventdInfo.IsSpecialName; var mapped = typeMap.Select(map => new { ContractType = map.ServiceType, ImplementationType = map.ConcreteType, ContractEvents = map.ServiceType.GetPublicEvents().Where(eventPredicate), EventsImpl = map.ConcreteType.GetPublicEvents().ToSet(eventPredicate), }); var mappedEventsEnumerable = mapped.SelectMany(map => { var events = map.ContractEvents; return(events.Select(@event => { var match = @event.SelectFirst(map.EventsImpl, (c, impl) => c.GetAddMethod().IsMatchedTo(impl.GetAddMethod()), (c, impl) => new { EventImpl = impl, ContractEvent = c }); return new EventMap(map.ContractType, map.ImplementationType, match.ContractEvent, match.EventImpl); })); }); mappedEvents = mappedEventsEnumerable.ToListOf <IEventMap>(); }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies, bool isComposite = false) { var name = typeMap.Name ?? typeMap.ServiceType.GetNameFromAttribute() ?? typeMap.ConcreteType.GetNameFromAttribute(); if (name.IsNotNullOrEmpty()) { typeMap = new TypeMap(typeMap.ServiceType, typeMap.ConcreteType, name); } regisrty.Register(typeMap, dependencies, isComposite); }
private bool IsAtomComposite(Type compositeType, ITypeMapCollection mixinsMap) { if (mixinsMap.Count == 1) { var mixinMap = mixinsMap.First(); return ReferenceEquals(mixinMap.ServiceType, compositeType); } return false; }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies, bool isComposite = false) { var name = typeMap.Name ?? typeMap.ServiceType.GetNameFromAttribute() ?? typeMap.ConcreteType.GetNameFromAttribute(); if (name.IsNotNullOrEmpty()) { typeMap = new TypeMap(typeMap.ServiceType, typeMap.ConcreteType, name); } regisrty.Register(typeMap, dependencies, isComposite); }
private bool IsAtomComposite(Type compositeType, ITypeMapCollection mixinsMap) { if (mixinsMap.Count == 1) { var mixinMap = mixinsMap.First(); return(ReferenceEquals(mixinMap.ServiceType, compositeType)); } return(false); }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false) { var serviceType = typeMap.ServiceType; var concreteType = typeMap.ConcreteType; IRegistration compositeRegistration = null; var castAs = serviceType.GetTypeFromAttribute(); var disposable = serviceType.GetDisposableFromAttribute(); compositeRegistration = isComposite ? new CompositeTypeRegistration(container, typeMap, dependencies, castAs, disposable) : new CompositeFrameworkRegistration(container, typeMap, dependencies, castAs, disposable); container.Register(compositeRegistration); }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies = null) { container.Configure(x => { var use = x.For(typeMap.ServiceType) .Use(typeMap.ConcreteType); if (typeMap.Name.IsNotNullOrEmpty()) { use.Named(typeMap.Name); } if (dependencies.IsNotNullOrEmpty()) { x.For(typeMap.ServiceType).Use("composite", BuildExpression(typeMap, dependencies)); } }); }
private void MapEvents(Type aspectDeclaringType, ITypeMapCollection typeMap) { var events = aspectDeclaringType.GetPublicEvents(); var eventMapper = new EventMapper(typeMap); var mappedEventsEnumerable = eventMapper.Select(map => { var aspectEvent = events.FirstOrDefault(@event => { return(@event.IsMatchedTo(map.ContractMember)); }); return(new AspectEventMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectEvent)); }); mappedEvents = mappedEventsEnumerable.ToList <IAspectEventMap>(); }
private void MapProperties(Type aspectDeclaringType, ITypeMapCollection typeMap) { var properties = aspectDeclaringType.GetPublicProperties(); var propertyMapper = new PropertyMapper(typeMap); var mappedPropertiesEnumerable = propertyMapper.Select(map => { var aspectProperty = properties.FirstOrDefault(property => { return(property.IsMatchedTo(map.ContractMember)); }); return(new AspectPropertyMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectProperty)); }); mappedProperties = mappedPropertiesEnumerable.ToList <IAspectPropertyMap>(); }
private void MapMethods(Type aspectDeclaringType, ITypeMapCollection typeMap) { var methods = aspectDeclaringType.GetPublicMethods(); var methodMapper = new MethodMapper(typeMap); var mappedMethodsEnumerable = methodMapper.Select(map => { var aspectMethod = methods.FirstOrDefault(method => { return(method.IsMatchedTo(map.ContractMember)); }); return(new AspectMethodMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectMethod)); }); mappedMethods = mappedMethodsEnumerable.ToList <IAspectMethodMap>(); }
private void MapEvents(Type aspectDeclaringType, ITypeMapCollection typeMap) { var events = aspectDeclaringType.GetPublicEvents(); var eventMapper = new EventMapper(typeMap); var mappedEventsEnumerable = eventMapper.Select(map => { var aspectEvent = events.FirstOrDefault(@event => { return @event.IsMatchedTo(map.ContractMember); }); return new AspectEventMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectEvent); }); mappedEvents = mappedEventsEnumerable.ToList<IAspectEventMap>(); }
private Func <IContext, object> BuildExpression(TypeMap typeMap, ITypeMapCollection dependencies) { var contextParameter = Expression.Parameter(typeof(IContext), "context"); var @params = dependencies.ToArray(d => d.ServiceType); var ctorInfo = typeMap.ConcreteType.GetConstructor(@params); var genericMethodInfo = typeof(IContext).GetMethods().First(method => { return(method.Name.Equals("GetInstance") && method.IsGenericMethodDefinition && method.GetParameters().Length == 1); }); var getInstanceCallExpressions = dependencies.Select(dependency => { var nameParam = Expression.Constant(dependency.Name, typeof(string)); var methodInfo = genericMethodInfo.MakeGenericMethod(new[] { dependency.ServiceType }); return(Expression.Call(contextParameter, methodInfo, new[] { nameParam })); }); var lambda = Expression.Lambda <Func <IContext, object> >( Expression.New(ctorInfo, getInstanceCallExpressions), contextParameter); return(lambda.Compile()); }
internal CompositeWeavingStrategy(IAspectTypeDefinition typeDefinition, ITypeMapCollection mixins, IEnumerable <IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry) : base(typeDefinition, mixins, methodWeavers, registry) { }
public AspectMemberMapper(Type aspectDeclaringType, ITypeMapCollection typeMap) { MapEvents(aspectDeclaringType, typeMap); MapMethods(aspectDeclaringType, typeMap); MapProperties(aspectDeclaringType, typeMap); }
public AspectMemberMapper(Type aspectDeclaringType, ITypeMapCollection typeMap) { MapEvents(aspectDeclaringType, typeMap); MapMethods(aspectDeclaringType, typeMap); MapProperties(aspectDeclaringType, typeMap); }
private void MapProperties(Type aspectDeclaringType, ITypeMapCollection typeMap) { var properties = aspectDeclaringType.GetPublicProperties(); var propertyMapper = new PropertyMapper(typeMap); var mappedPropertiesEnumerable = propertyMapper.Select(map => { var aspectProperty = properties.FirstOrDefault(property => { return property.IsMatchedTo(map.ContractMember); }); return new AspectPropertyMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectProperty); }); mappedProperties = mappedPropertiesEnumerable.ToList<IAspectPropertyMap>(); }
internal CompositeTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection) : base(mixinsType, mixinsMap) { this.compositeMemberCollection = compositeMemberCollection; }
/// <summary> /// Constructor. /// </summary> /// <param name="typeMaps">A list of type maps, keyed by base type. /// Each entry in a typemap consists of a string representation of /// a sub type, along with the actual subclass type.</param> public ApiContractResolver(ITypeMapCollection typeMaps) { NamingStrategy = new CamelCaseNamingStrategy(); _typeMaps = typeMaps ?? new TypeMapCollection(); }
public MixinsTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap) { Type = mixinsType; this.mixinsMap = mixinsMap; }
internal CompositeTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection) : base(contractType, mixinsMap) { typeDefinitionInitializer = new CompositeTypeDefinition(Type, mixinsMap, compositeMemberCollection); }
public MixinsTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap) : base(contractType, mixinsMap) { typeDefinitionInitializer = new MixinsTypeDefinition(Type, mixinsMap); }
internal CompositeTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection) : base(mixinsType, mixinsMap) { this.compositeMemberCollection = compositeMemberCollection; }
protected AbstractTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap) { Type = contractType; this.mixinsMap = mixinsMap; }
/// <summary> /// Registers dependencies for json serialization. /// </summary> public static void RegisterJsonSerialization(this ContainerBuilder builder, ITypeMapCollection typeMaps) { builder.RegisterType <JsonSettingsProvider>().As <IJsonSettingsProvider>().InstancePerLifetimeScope(); builder.RegisterType <ModelSerializer>().As <IJsonSerializer>().InstancePerLifetimeScope(); builder.RegisterInstance(typeMaps).As <ITypeMapCollection>(); }
internal CompositeWeavingStrategy(IAspectTypeDefinition typeDefinition, ITypeMapCollection mixins, IEnumerable<IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry) : base(typeDefinition, mixins, methodWeavers, registry) { }
/// <summary> /// Constructor. /// </summary> public JsonSettingsProvider(ITypeMapCollection typeMaps) { _typeMaps = typeMaps; }
/// <summary> /// Constructor. /// </summary> /// <param name="typeMaps">A list of type maps, keyed by base type. /// Each entry in a typemap consists of a string representation of /// a sub type, along with the actual subclass type.</param> public ApiContractResolver(ITypeMapCollection typeMaps) { NamingStrategy = new CamelCaseNamingStrategy(); _typeMaps = typeMaps ?? new TypeMapCollection(); }
/// <summary> /// Constructor. /// </summary> public JsonSettingsProvider(ITypeMapCollection typeMaps) { _typeMaps = typeMaps; }
public override void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false) { RegisterImpl(new ReflectionRegistration(typeMap.ConcreteType, typeMap.ServiceType)); }
public MixinsTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap) : base(contractType, mixinsMap) { typeDefinitionInitializer = new MixinsTypeDefinition(Type, mixinsMap); }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false) { registry.Register(typeMap, dependencies); }
/// <summary> /// Registers dependencies for json serialization. /// </summary> public static void RegisterJsonSerialization(this ContainerBuilder builder, ITypeMapCollection typeMaps) { builder.RegisterType<JsonSettingsProvider>().As<IJsonSettingsProvider>().InstancePerLifetimeScope(); builder.RegisterType<ModelSerializer>().As<IJsonSerializer>().InstancePerLifetimeScope(); builder.RegisterInstance(typeMaps).As<ITypeMapCollection>(); }
protected AbstractTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap) { Type = contractType; this.mixinsMap = mixinsMap; }
public void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false) { registry.Register(typeMap, dependencies, isComposite); }
public MixinsTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap) { Type = mixinsType; this.mixinsMap = mixinsMap; }
private void MapMethods(Type aspectDeclaringType, ITypeMapCollection typeMap) { var methods = aspectDeclaringType.GetPublicMethods(); var methodMapper = new MethodMapper(typeMap); var mappedMethodsEnumerable = methodMapper.Select(map => { var aspectMethod = methods.FirstOrDefault(method => { return method.IsMatchedTo(map.ContractMember); }); return new AspectMethodMap(map.ContractType, map.ImplementationType, map.ContractMember, map.ImplementationMember, aspectMethod); }); mappedMethods = mappedMethodsEnumerable.ToList<IAspectMethodMap>(); }
public override void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false) { RegisterImpl(new ReflectionRegistration(typeMap.ConcreteType, typeMap.ServiceType)); }
internal CompositeTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection) : base(contractType, mixinsMap) { typeDefinitionInitializer = new CompositeTypeDefinition(Type, mixinsMap, compositeMemberCollection); }