Example #1
0
        public void Resolver(IResolverContext context, IDependencyResolver resolver)
        {
            var args = context.HasImplementationType() && context.HasPublicConstructor()
                ? ResolverHelper.GetConstructorParameters(
                context.Dependency.GetImplementationType(), resolver)
                : ArrayExtends.Empty <object>();

            context.Resolved = CompileCacheManager.GetCache(context.Dependency, resolver, args);

            context.Handled = context.Resolved != null && !PropertyCacheManager.Any(context.Dependency);
        }
        public void Resolver(IResolverContext context, IDependencyResolver resolver)
        {
            try
            {
                var args = context.HasImplementationType() && context.HasPublicConstructor()
                    ? ResolverHelper.GetConstructorParameters(
                    context.Dependency.GetImplementationType(), resolver)
                    : ArrayExtends.Empty <object>();

                context.Resolved = CompileCacheManager.GetOrSetCache(context.Dependency,
                                                                     () => CreateDelegate(context.Resolved as Expression)).
                                   Invoke(resolver, args);

                CacheResolved(context, resolver);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"未能创建类型\"{context.Dependency.ServiceType}\"的实例。", ex);
            }
        }