public void ConfigureMyServices(IMyServiceCollection services) { // 线程间共享 services.AddScoped <IMain, Main>(); services.AddScoped <IThreadA, ThreadA>(); services.AddScoped <IThreadB, ThreadB>(); // 单例 services.AddSingleton <IThreadC, ThreadC>(); //// 临时 //services.AddTransient<IThreadC, ThreadC>(); }
public static void AddSingleton <T1, T2>(this IMyServiceCollection services) where T2 : T1 { serviceTypes.Add(typeof(T1), MyServiceDescriptor.Singleton(typeof(T2))); }
public static void AddSingleton <T1>(this IMyServiceCollection services) { serviceTypes.Add(typeof(T1), MyServiceDescriptor.Singleton(typeof(T1))); }
public static void AddTransient <T1, T2>(this IMyServiceCollection services) where T2 : T1 { serviceTypes.Add(typeof(T1), MyServiceDescriptor.Transient(typeof(T2))); }
public static void AddTransient <T1>(this IMyServiceCollection services) { serviceTypes.Add(typeof(T1), MyServiceDescriptor.Transient(typeof(T1))); }