平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SignalRComponent.cs 1.0 KiB

3 months ago
12345678910111213141516171819202122
  1. namespace SafeCampus.Plugin.SignalR
  2. {
  3. /// <summary>
  4. /// SignalR组件
  5. /// </summary>
  6. public sealed class SignalRComponent : IServiceComponent
  7. {
  8. /// <summary>
  9. /// ConfigureServices中不能解析服务,比如App.GetService(),尤其是不能在ConfigureServices中获取诸如缓存等数据进行初始化,应该在Configure中进行
  10. /// 服务都还没初始化完成,会导致内存中存在多份 IOC 容器!!
  11. /// 正确应该在 Configure 中,这个时候服务(IServiceCollection 已经完成 BuildServiceProvider() 操作了
  12. /// </summary>
  13. /// <param name="services"></param>
  14. /// <param name="componentContext"></param>
  15. public void Load(IServiceCollection services, ComponentContext componentContext)
  16. {
  17. Console.WriteLine("注册SignalR插件");
  18. services.AddSignalR();//注册SignalR
  19. services.AddSingleton<IUserIdProvider, UserIdProvider>();//用户ID提供器
  20. }
  21. }
  22. }