/// <summary> /// 注册一个扩展。 /// </summary> /// <param name="kernelBuilder">内核建设者。</param> /// <param name="assembly">扩展程序集。</param> /// <param name="isMinimumShellDescriptor">是否迷你外壳描述符。</param> /// <returns>内核建设者。</returns> public static IKernelBuilder RegisterExtension(this IKernelBuilder kernelBuilder, Assembly assembly, bool isMinimumShellDescriptor) { kernelBuilder.OnStarting( builder => { builder.RegisterType <ExtensionFolders>().As <IExtensionFolders>().SingleInstance(); builder.RegisterType <ExtensionMinimumShellDescriptorProvider>().As <IMinimumShellDescriptorProvider>().SingleInstance(); }, "RegisterExtensions"); var description = new ExtensionFolders.SimpleExtensionDescription { Id = assembly.GetName().Name, Type = "Module", Location = "~/" }; Descriptions.Add(description); if (isMinimumShellDescriptor) { ExtensionMinimumShellDescriptorProvider.Features.Add(description.Id); } return(kernelBuilder); }
/// <summary> /// 使用数据。 /// </summary> /// <param name="kernelBuilder">内核建设者。</param> /// <param name="dataBuilder">数据建设者。</param> public static void UseData(this IKernelBuilder kernelBuilder, Action <IDataBuilder> dataBuilder) { kernelBuilder.OnStarting(builder => builder.RegisterType <CompositionStrategyProvider>().As <ICompositionStrategyProvider>().SingleInstance()); if (dataBuilder != null) { dataBuilder(new DataBuilder(kernelBuilder)); } }
/// <summary> /// 使用缓存。 /// </summary> /// <param name="kernelBuilder">内核建设者。</param> /// <param name="cachingBuilder">缓存建设动作。</param> public static void UseCaching(this IKernelBuilder kernelBuilder, Action <ICachingBuilder> cachingBuilder) { kernelBuilder.OnStarting(builder => { builder.RegisterType <DefaultCacheContextAccessor>().As <ICacheContextAccessor>().SingleInstance(); builder.RegisterType <DefaultParallelCacheContext>().As <IParallelCacheContext>().SingleInstance(); builder.RegisterType <DefaultAsyncTokenProvider>().As <IAsyncTokenProvider>().SingleInstance(); }); cachingBuilder(new CachingBuilder(kernelBuilder)); }
/// <summary> /// 使用数据。 /// </summary> /// <param name="kernelBuilder">内核建设者。</param> public static void UseDataBase(this IKernelBuilder kernelBuilder) { // kernelBuilder.RegisterExtension(typeof (BuilderExtensions).Assembly); kernelBuilder.OnStarting( builder => { builder.RegisterType <DbConnectionFactory>().As <IDbConnectionFactory>().InstancePerDependency(); builder.RegisterType <SqlDbConnectionProvider>().As <IDbConnectionProvider>().SingleInstance(); }); }