public static IContentBuilder AddContent <TDependency>(this IExtensionBuilder parentBuilder, Action <TDependency> configureDependency = null, Func <IExtensionBuilder, TDependency, IContentBuilder> builderFactory = null) where TDependency : ContentBuilderDependency { if (!parentBuilder.TryGetBuilder <IDataBuilder>(out var dataBuilder)) { throw new NotSupportedException($"You need to register to builder.{nameof(DataBuilderExtensions.AddData)}()."); } // Clear Options Cache ConsistencyOptionsCache.TryRemove <ContentBuilderOptions>(); // Add Builder Dependency var dependency = parentBuilder.AddBuilderDependency(out var dependencyType, configureDependency); parentBuilder.Services.TryAddReferenceBuilderDependency <ContentBuilderDependency>(dependency, dependencyType); // Create Builder var contentBuilder = builderFactory.NotNullOrDefault(() => (b, d) => new ContentBuilder(b, d)).Invoke(parentBuilder, dependency); var parameterMapper = ContentAccessorTypeParameterMappingHelper .ParseMapper(dataBuilder.AccessorTypeParameterMapper); contentBuilder.SetProperty(p => p.AccessorTypeParameterMapper, parameterMapper); return(contentBuilder); }
public static IDataBuilder AddData <TDependency>(this IExtensionBuilder parentBuilder, Action <TDependency> configureDependency = null, Func <IExtensionBuilder, TDependency, IDataBuilder> builderFactory = null) where TDependency : DataBuilderDependency { // Clear Options Cache ConsistencyOptionsCache.TryRemove <DataBuilderOptions>(); // Add Builder Dependency var dependency = parentBuilder.AddBuilderDependency(out var dependencyType, configureDependency); parentBuilder.Services.TryAddReferenceBuilderDependency <DataBuilderDependency>(dependency, dependencyType); // Add Dependencies if (dependency.SupportsEntityFrameworkDesignTimeServices) { parentBuilder.Services .AddEntityFrameworkDesignTimeServices(); // TypeMappingSourceDependencies 默认被重复注册导致依赖异常,须移除后重新注册 parentBuilder.Services.TryRemoveAll <TypeMappingSourceDependencies>(); parentBuilder.Services.AddSingleton <TypeMappingSourceDependencies>(); } // Create Builder return(builderFactory.NotNullOrDefault(() => (b, d) => new DataBuilder(b, d)).Invoke(parentBuilder, dependency)); }
public static INetworkBuilder AddNetwork <TDependency>(this IExtensionBuilder parentBuilder, Action <TDependency> configureDependency = null, Func <IExtensionBuilder, TDependency, INetworkBuilder> builderFactory = null) where TDependency : NetworkBuilderDependency { if (!parentBuilder.ContainsBuilder <IEncryptionBuilder>()) { parentBuilder .AddEncryption() .AddDeveloperGlobalSigningCredentials(); } // Clear Options Cache ConsistencyOptionsCache.TryRemove <NetworkBuilderOptions>(); // Add Builder Dependency var dependency = parentBuilder.AddBuilderDependency(out var dependencyType, configureDependency); parentBuilder.Services.TryAddReferenceBuilderDependency <NetworkBuilderDependency>(dependency, dependencyType); // Add Dependencies parentBuilder.Services .AddHttpClient(); // Create Builder return(builderFactory.NotNullOrDefault(() => (b, d) => new NetworkBuilder(b, d)).Invoke(parentBuilder, dependency)); }
/// <summary> /// 添加 Librame。 /// </summary> /// <typeparam name="TDependency">指定的依赖类型。</typeparam> /// <param name="services">给定的 <see cref="IServiceCollection"/>。</param> /// <param name="configureDependency">给定的配置依赖动作方法(可选)。</param> /// <param name="builderFactory">给定创建核心构建器的工厂方法(可选)。</param> /// <returns>返回 <see cref="ICoreBuilder"/>。</returns> public static ICoreBuilder AddLibrame <TDependency>(this IServiceCollection services, Action <TDependency> configureDependency = null, Func <IServiceCollection, TDependency, ICoreBuilder> builderFactory = null) where TDependency : CoreBuilderDependency, new() { // Use PreStarter services.AddLibramePreStarterFactory <PreStarterFactory>(); services.UsePreStarter(); // Clear Options Cache ConsistencyOptionsCache.TryRemove <CoreBuilderOptions>(); // Add Builder Dependency var dependency = services.AddBuilderDependencyRoot(out var dependencyType, configureDependency); services.TryAddReferenceBuilderDependency <CoreBuilderDependency>(dependency, dependencyType); // Add Dependencies services .AddOptions() .AddLogging(dependency.ConfigureLoggingBuilder) .AddLocalization() .AddMemoryCache() .AddDistributedMemoryCache(); // Create Builder return(builderFactory.NotNullOrDefault(() => (s, d) => new CoreBuilder(s, d)).Invoke(services, dependency)); }
public static IDrawingBuilder AddDrawing <TDependency>(this IExtensionBuilder parentBuilder, Action <TDependency> configureDependency = null, Func <IExtensionBuilder, TDependency, IDrawingBuilder> builderFactory = null) where TDependency : DrawingBuilderDependency { // Clear Options Cache ConsistencyOptionsCache.TryRemove <DrawingBuilderOptions>(); // Add Builder Dependency var dependency = parentBuilder.AddBuilderDependency(out var dependencyType, configureDependency); parentBuilder.Services.TryAddReferenceBuilderDependency <DrawingBuilderDependency>(dependency, dependencyType); // Create Builder return(builderFactory.NotNullOrDefault(() => (b, d) => new DrawingBuilder(b, d)).Invoke(parentBuilder, dependency)); }
public static IPortalBuilder AddPortal <TDependency, TUser>(this IExtensionBuilder parentBuilder, Action <TDependency> configureDependency = null, Func <Type, IExtensionBuilder, TDependency, IPortalBuilder> builderFactory = null) where TDependency : PortalBuilderDependency where TUser : class { // Clear Options Cache ConsistencyOptionsCache.TryRemove <PortalBuilderOptions>(); // Add Builder Dependency var dependency = parentBuilder.AddBuilderDependency(out var dependencyType, configureDependency); parentBuilder.Services.TryAddReferenceBuilderDependency <PortalBuilderDependency>(dependency, dependencyType); // Create Builder return(builderFactory.NotNullOrDefault(() => (u, b, d) => new PortalBuilder(u, b, d)).Invoke(typeof(TUser), parentBuilder, dependency)); }
public static INetworkBuilder AddDotNetty <TDependency>(this INetworkBuilder builder, Action <TDependency> configureDependency = null) where TDependency : DotNettyDependency { // Clear Options Cache ConsistencyOptionsCache.TryRemove <DotNettyOptions>(); AddDotNettyServiceCharacteristics(); // Add Builder Dependency var dependency = builder.AddBuilderDependency(out var dependencyType, configureDependency); builder.Services.TryAddReferenceBuilderDependency <DotNettyDependency>(dependency, dependencyType); builder.SetProperty(p => p.DotNettyDependency, dependency); // Configure Builder return(builder.AddDotNettyServices()); }