コード例 #1
0
 public CommandDispatcher <TResult> WithCache(CacheConfig cacheConfig)
 {
     this.cacheConfig = cacheConfig;
     if (UseCache)
     {
         memoryCache = LayIMServiceLocator.GetService <IMemoryCache>();
     }
     return(this);
 }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <summary>
        /// 获取当前用户ID
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetCurrentUserId(HttpContext context)
        {
            var userFactory = LayIMServiceLocator.GetService <ILayIMUserFactory>();

            return(userFactory.GetUserId(context));
        }
コード例 #6
0
 private static Lazy <TService> GetLazyService <TService>()
 {
     return(new Lazy <TService>(() => LayIMServiceLocator.GetService <TService>()));
 }