private IEnumerable<IApiMethodCall> RouteEntryPoint(ContainerRegistration apiEntryPoint)
        {
            try
            {
                //Get all methods
                MethodInfo[] methods = apiEntryPoint.MappedToType.GetMethods(BindingFlags.Instance | BindingFlags.Public);

                var gloabalFilters =
                    apiEntryPoint.MappedToType.GetCustomAttributes(typeof(ApiCallFilter), true).Cast<ApiCallFilter>().ToList();
                gloabalFilters.AddRange(apiEntryPoint.MappedToType.Assembly.GetCustomAttributes(typeof(ApiCallFilter), true).Cast<ApiCallFilter>());
                gloabalFilters.AddRange(Container.ResolveAll<ApiCallFilter>());//Add gloably registered filters

                return (from methodInfo in methods.Where(x => !x.IsConstructor)
                        let attr =
                            methodInfo.GetCustomAttributes(typeof(ApiAttribute), true).Cast<ApiAttribute>().FirstOrDefault()
                        let cache =
                            methodInfo.GetCustomAttributes(typeof(CacheAttribute), true).Cast<CacheAttribute>().
                            FirstOrDefault()
                        let filters = methodInfo.GetCustomAttributes(typeof(ApiCallFilter), true).Cast<ApiCallFilter>()
                        let poll = methodInfo.GetCustomAttributes(typeof(PollAttribute), true).Cast<PollAttribute>().
                            FirstOrDefault()
                        where attr != null
                        select ToApiMethodCall(methodInfo, apiEntryPoint, attr, cache, poll, filters, gloabalFilters)).ToList();
            }
            catch (Exception err)
            {
                Log.Error(err, "Could not load apiEntryPoint {0}", apiEntryPoint.Name);
                return Enumerable.Empty<IApiMethodCall>();
            }
        }
        private IApiMethodCall ToApiMethodCall(MethodInfo methodInfo, ContainerRegistration apiEntryPointType, ApiAttribute attr, CacheAttribute cache, PollAttribute poll, IEnumerable<ApiCallFilter> filters, List<ApiCallFilter> gloabalFilters)
        {
            var methodCall = Container.Resolve<IApiMethodCall>();
            methodCall.MethodCall = methodInfo;
            methodCall.Name = apiEntryPointType.Name;
            methodCall.ApiClassType = apiEntryPointType.MappedToType;
            methodCall.HttpMethod = attr.Method;
            methodCall.RoutingUrl = ExtractPath(attr.Path);
            methodCall.CacheTime = cache != null ? cache.CacheTime : 0;
            methodCall.Constraints = ExtractConstraints(attr.Path, attr.Method);
            methodCall.RequiresAuthorization = attr.RequiresAuthorization;
            methodCall.SupportsPoll = poll != null;
            methodCall.RoutingPollUrl = poll != null ? poll.PollUrl : string.Empty;

            //Add filters
            gloabalFilters.AddRange(filters);
            methodCall.Filters = gloabalFilters;

            return methodCall;
        }
Exemple #3
0
 public NamedRegistration(ContainerRegistration r)
 {
     Name = r.Name;
     MappedToType = r.MappedToType;
     LifeTimeManagerType = r.LifetimeManagerType;
 }
Exemple #4
0
 public NamelessRegistration(ContainerRegistration r)
 {
     RegisteredType = r.RegisteredType;
     MappedToType = r.MappedToType;
     LifeTimeManagerType = r.LifetimeManagerType;
 }
 private static string ToRegistrationString(ContainerRegistration registration)
 {
     return registration.RegisteredType.FullName + " - " + registration.MappedToType.FullName +
            Named(registration) + AsSingleton(registration);
 }
 private static string Named(ContainerRegistration registration)
 {
     return registration.Name != null ? string.Format(" named \"{0}\"", registration.Name) : null;
 }
 private static string AsSingleton(ContainerRegistration registration)
 {
     return registration.LifetimeManager != null ? " with " + registration.LifetimeManager.GetType().Name : null;
 }
        private Type TypeToGetResolved(Type serviceKey, ContainerRegistration registration)
        {
            if (registration != null)
            {
                return registration.MappedToType;
            }

            if (serviceKey.IsClass && !serviceKey.IsAbstract)
            {
                return serviceKey;
            }
            return null;
        }
 private ResolverOverride ResolveParameterName(Type serviceKey, ContainerRegistration registration,
     ref Type resolvedType, InjectionParameter injectionParameter)
 {
     resolvedType = resolvedType ?? TypeToGetResolved(serviceKey, registration);
     ParameterInfo constructorParameter = resolvedType.GetConstructors().SelectMany(c => c.GetParameters())
         .First(p => p.ParameterType.IsInstanceOfType(injectionParameter.Value));
     return new ParameterOverride(constructorParameter.Name, injectionParameter.Value);
 }
 private ResolverOverride[] ModifyParameters(Type serviceKey, ContainerRegistration registration,
     InjectionParameter[] parameters)
 {
     if (parameters == null || parameters.Length == 0)
     {
         return null;
     }
     Type resolvedType = null;
     return
         parameters.Select(
             p =>
                 string.IsNullOrEmpty(p.Key)
                     ? ResolveParameterName(serviceKey, registration, ref resolvedType, p)
                     : new ParameterOverride(p.Key, p.Value))
             .ToArray();
 }