Program.cs
EnginContex为静态类
//注册服务 EnginContext.SetServiceProvider(app.Services);
EnginContex.cs
public sealed class EnginContext { private static IServiceProvider _serviceProvider; [MethodImpl(MethodImplOptions.Synchronized)] public static void SetServiceProvider(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } public static T Resolve<T>() { return _serviceProvider.GetService<T>(); } }
使用方法:
public sealed class T { public static T Instance => EnginContext.Resolve<T>(); } ---------------- T.Instance.方法()
标签:serviceProvider,手动,Instance,EnginContext,static,cs,net,public,注入 From: https://www.cnblogs.com/Andy-Blog/p/18100991