Example #1
0
 public void TestCanResolve()
 {
     using (var swe = new Sweph())
     {
         Assert.IsFalse(swe.Dependencies.CanResolve(null));
         Assert.IsFalse(DependencyExtensions.CanResolve <Type1>(null));
         Assert.IsFalse(swe.Dependencies.CanResolve(typeof(Type1)));
         Assert.IsFalse(swe.Dependencies.CanResolve <Type1>());
         swe.Dependencies.Register <Type1>(cnt => new Type1 {
             Value = 123
         }, true);
         Assert.IsFalse(swe.Dependencies.CanResolve(null));
         Assert.IsFalse(DependencyExtensions.CanResolve <Type1>(null));
         Assert.IsTrue(swe.Dependencies.CanResolve(typeof(Type1)));
         Assert.IsTrue(swe.Dependencies.CanResolve <Type1>());
     }
 }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddOptions();

            // 加载配置
            services.Configure <MessageConfigure>(Configuration.GetSection("Message"));

            // 练手项目,建议修改
            services.AddSingleton(redisHelper =>
            {
                var redisAddr = Configuration.GetValue <string>("Redis:RedisAddr");
                var redisDb   = Configuration.GetValue <int>("Redis:RedisDb");
                var prefixKey = Configuration.GetValue <string>("Redis:PrefixKey") ?? "prefix_";
                return(DependencyExtensions.UseRedis(redisAddr, redisDb, prefixKey));
            });

            services.AddSingleton <ChatService>();
            services.AddSingleton <IChannelManage, ChannelManage>();
            services.AddSingleton <RedisMessageManage>();
            services.AddHostedService <AppBackgroundService>();
        }