Пример #1
0
        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>();
        }
Пример #2
0
        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>();
        }
Пример #3
0
        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>();
        }
Пример #4
0
 public MixinsWeaverStrategy(ITypeDefinition typeDefinition, ITypeMapCollection mixinsMap, IEnumerable <IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry)
 {
     this.registry       = registry;
     this.mixinsMap      = mixinsMap;
     this.methodWeavers  = methodWeavers;
     this.typeDefinition = typeDefinition;
 }
Пример #5
0
        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>();
        }
Пример #6
0
 public MixinsWeaverStrategy(ITypeDefinition typeDefinition, ITypeMapCollection mixinsMap, IEnumerable<IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry)
 {
     this.registry = registry;
     this.mixinsMap = mixinsMap;
     this.methodWeavers = methodWeavers;
     this.typeDefinition = typeDefinition;
 }
Пример #7
0
        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>();
        }
Пример #8
0
        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>();
        }
Пример #9
0
        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);
        }
Пример #10
0
        private bool IsAtomComposite(Type compositeType, ITypeMapCollection mixinsMap)
        {
            if (mixinsMap.Count == 1) {
                var mixinMap = mixinsMap.First();

                return ReferenceEquals(mixinMap.ServiceType, compositeType);
            }

            return false;
        }
Пример #11
0
        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);
        }
Пример #14
0
        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));
                }
            });
        }
Пример #15
0
        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>();
        }
Пример #16
0
        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>();
        }
Пример #17
0
        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>();
        }
Пример #18
0
        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>();
        }
Пример #19
0
        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());
        }
Пример #20
0
 internal CompositeWeavingStrategy(IAspectTypeDefinition typeDefinition, ITypeMapCollection mixins, IEnumerable <IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry)
     : base(typeDefinition, mixins, methodWeavers, registry)
 {
 }
Пример #21
0
 public AspectMemberMapper(Type aspectDeclaringType, ITypeMapCollection typeMap)
 {
     MapEvents(aspectDeclaringType, typeMap);
     MapMethods(aspectDeclaringType, typeMap);
     MapProperties(aspectDeclaringType, typeMap);
 }
Пример #22
0
 public AspectMemberMapper(Type aspectDeclaringType, ITypeMapCollection typeMap)
 {
     MapEvents(aspectDeclaringType, typeMap);
     MapMethods(aspectDeclaringType, typeMap);
     MapProperties(aspectDeclaringType, typeMap);
 }
Пример #23
0
        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>();
        }
Пример #24
0
 internal CompositeTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection)
     : base(mixinsType, mixinsMap)
 {
     this.compositeMemberCollection = compositeMemberCollection;
 }
Пример #25
0
 /// <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();
 }
Пример #26
0
 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);
 }
Пример #28
0
 public MixinsTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap)
     : base(contractType, mixinsMap)
 {
     typeDefinitionInitializer = new MixinsTypeDefinition(Type, mixinsMap);
 }
Пример #29
0
 internal CompositeTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap, ICompositeMemberCollection compositeMemberCollection)
     : base(mixinsType, mixinsMap)
 {
     this.compositeMemberCollection = compositeMemberCollection;
 }
Пример #30
0
 protected AbstractTypeDefinitionWeaver(Type contractType, ITypeMapCollection mixinsMap)
 {
     Type = contractType;
     this.mixinsMap = mixinsMap;
 }
Пример #31
0
 /// <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>();
 }
Пример #32
0
 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;
 }
Пример #34
0
 /// <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();
 }
Пример #35
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public JsonSettingsProvider(ITypeMapCollection typeMaps)
 {
     _typeMaps = typeMaps;
 }
Пример #36
0
 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);
 }
Пример #38
0
 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;
 }
Пример #41
0
 public void Register(TypeMap typeMap, ITypeMapCollection dependencies = null, bool isComposite = false)
 {
     registry.Register(typeMap, dependencies, isComposite);
 }
Пример #42
0
 public MixinsTypeDefinition(Type mixinsType, ITypeMapCollection mixinsMap)
 {
     Type           = mixinsType;
     this.mixinsMap = mixinsMap;
 }
Пример #43
0
        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>();
        }
Пример #44
0
 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);
 }