public CommandDispatcher <TResult> WithCache(CacheConfig cacheConfig) { this.cacheConfig = cacheConfig; if (UseCache) { memoryCache = LayIMServiceLocator.GetService <IMemoryCache>(); } return(this); }
/// <summary> /// 获取当前用户ID /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetCurrentUserId(HttpContext context) { //先使用用户自定义的 var userFactory = LayIMServiceLocator.Options.UserFactory; if (userFactory == null) { //在使用框架自带的 userFactory = LayIMServiceLocator.GetService <ILayIMUserFactory>(); } if (userFactory == null) { return(null); } return(userFactory.GetUserId(context)); }
public static IApplicationBuilder UseLayIM(this IApplicationBuilder app, Action <LayIMOptions> initFunc = null) { var options = new LayIMOptions(); initFunc?.Invoke(options); app.UseMiddleware <LayIMMiddleware>(options); //设置全局配置 LayIMServiceLocator.SetOptions(options); app.UseFileServer(new FileServerOptions { RequestPath = options.ApiPrefix, FileProvider = new EmbeddedFileProvider(typeof(LayIMBuilderExtensions).GetTypeInfo().Assembly, LayIMEmbeddedFileNamespace), }); return(app); }
/// <summary> /// 使用SignalR通信 /// </summary> /// <param name="services"></param> /// <param name="configure"></param> public static IServiceCollection AddSignalR(this IServiceCollection services, Action <LayIMHubOptions> configure) { var options = new LayIMHubOptions(); configure?.Invoke(options); var signalRServerBuilder = services.AddSignalR(options.HubConfigure); if (options.UseRedis) { signalRServerBuilder.AddRedis(options.RedisConfiguration, options.RedisConfigure); } //AddSignalR must be called before registering your custom SignalR services. services.AddSingleton <ILayIMAppBuilder, SignalRAppBuilder>(); services.AddSingleton <ILayIMServer, SignalRServer>(); services.AddScoped <ISignalRHandler, SignalRHandler>(); services.AddSingleton <IUserIdProvider, LayIMUserIdProvider>(); services.AddJwtBearer(); LayIMServiceLocator.SetServiceProvider(services.BuildServiceProvider()); return(services); }
/// <summary> /// 获取当前用户ID /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetCurrentUserId(HttpContext context) { var userFactory = LayIMServiceLocator.GetService <ILayIMUserFactory>(); return(userFactory.GetUserId(context)); }
private static Lazy <TService> GetLazyService <TService>() { return(new Lazy <TService>(() => LayIMServiceLocator.GetService <TService>())); }