src/ZKEACMS/Extend/ServiceCollectionExtend.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using ZKEACMS.DbConnectionPool;
using ZKEACMS.Event;

namespace ZKEACMS
{
    public static class ServiceCollectionExtend
    {
        public static void AddDbContextOptions<TDbContext>(this IServiceCollection services) where TDbContext : DbContext
        {
            services.AddScoped<DbContextOptions<TDbContext>>(sp =>
            {
                IConnectionHolder holder = sp.GetService<IConnectionHolder>();
                IDatabaseConfiguring configure = sp.GetService<IDatabaseConfiguring>();
                DbContextOptionsBuilder<TDbContext> optBuilder = new DbContextOptionsBuilder<TDbContext>();
                configure.OnConfiguring(optBuilder, holder.DbConnection);
                return optBuilder.Options;
            });
        }
        public static void RegistEvent<Handler>(this IServiceCollection services, params string[] events)
            where Handler : class, IEventHandler
        {
            Type type = typeof(Handler);
            foreach (var name in events)
            {
                EventManager.RegistEvent(name, type);
            }
            services.AddScoped(type);
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。