static UnknownServiceResolverRule()
 {
     DependencyServiceResolverRule = Rules.Default.WithUnknownServiceResolvers(request => new DelegateFactory(_ =>
     {
         var targetType = request.ServiceType;
         if (!targetType.GetTypeInfo().IsInterface)
         {
             return null;
         }
         var method = typeof(DependencyService).GetTypeInfo().GetDeclaredMethod("Get");
         var genericMethod = method.MakeGenericMethod(targetType);
         return genericMethod.Invoke(null, new object[] { DependencyFetchTarget.GlobalInstance });
     }));
 }
Beispiel #2
0
        static partial void CompileToMethod(Expression <FactoryDelegate> factoryExpression, Rules rules, ref FactoryDelegate result)
        {
            if (!rules.CompilationToDynamicAssemblyEnabled)
            {
                return;
            }

            result.ThrowIf(result != null);

            var typeName    = "Factory" + Interlocked.Increment(ref _typeId);
            var typeBuilder = GetDynamicAssemblyModuleBuilder().DefineType(typeName, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract);

            var methodBuilder = typeBuilder.DefineMethod(
                "GetService",
                MethodAttributes.Public | MethodAttributes.Static,
                typeof(object),
                new[] { typeof(AppendableArray <object>), typeof(ContainerWeakRef), typeof(IScope) });

            factoryExpression.CompileToMethod(methodBuilder);

            var dynamicType = typeBuilder.CreateType();

            result = (FactoryDelegate)Delegate.CreateDelegate(typeof(FactoryDelegate), dynamicType.GetMethod("GetService"));
        }
Beispiel #3
0
partial         static void CompileToMethod(Expression<FactoryDelegate> factoryExpression, Rules rules, ref FactoryDelegate result)
        {
            if (!rules.FactoryDelegateCompilationToDynamicAssembly)
                return;

            result.ThrowIf(result != null);

            var typeName = "Factory" + Interlocked.Increment(ref _typeId);
            var typeBuilder = GetDynamicAssemblyModuleBuilder().DefineType(typeName, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract);

            var methodBuilder = typeBuilder.DefineMethod(
                "GetService",
                MethodAttributes.Public | MethodAttributes.Static,
                typeof(object),
                new[] { typeof(AppendableArray), typeof(IResolverContextProvider), typeof(IScope) });

            factoryExpression.CompileToMethod(methodBuilder);

            var dynamicType = typeBuilder.CreateType();
            result = (FactoryDelegate)Delegate.CreateDelegate(typeof(FactoryDelegate), dynamicType.GetMethod("GetService"));
        }