public static IServiceProvider BuildVerthandiAopServiceProvider(this IServiceCollection sc, IInterceptorGenerator[] interceptors, LoomOptions options = null) { var op = options ?? LoomOptions.CreateDefault(); var userFilterProxy = op.FilterProxy ?? ((ITypeSymbolInfo i) => true); var userFilterForDefaultImplement = op.FilterForDefaultImplement ?? ((ITypeSymbolInfo i) => true); op.FilterProxy = i => i.Namespace != null && AopUtils.CanAopType(i) && userFilterProxy(i); op.FilterForDefaultImplement = i => i.Namespace != null && AopUtils.CanDoDefaultImplement(i) && userFilterForDefaultImplement(i); var generator = new AopSourceGenerator(op, interceptors ?? new IInterceptorGenerator[0]); var types = sc.Select(i => i.ServiceType).Select(j => j.IsGenericType ? j.GetGenericTypeDefinition() : j).Distinct().ToArray(); var assembly = generator.Generate(new TypesSymbolSource(types)); DestinyExtensions.CleanCache(); GC.Collect(); return(sc.BuildAopServiceProvider(assembly)); }
public static R GenerateProxy <R>(Type type, ServiceLifetime lifetime = ServiceLifetime.Singleton, Action <IServiceCollection> action = null) { var generator = new AopSourceGenerator(options, new IInterceptorGenerator[] { new AddSomeTingsInterceptorGenerator() }); var assembly = generator.Generate(new TypesSymbolSource(type)); var services = new ServiceCollection(); if (action == null) { services.AddDestinyInterface <R>(lifetime); } else { action(services); } var provider = services.BuildAopServiceProvider(assembly); return(provider.GetRequiredService <R>()); }