Exemplo n.º 1
0
        /// <summary>
        /// 构造方法,初始化模块和服务
        /// </summary>
        public WebQQClient(Action <IServiceCollection> configureServices = null)
        {
            _services = new ServiceCollection();
            foreach (var service in CommonServices)
            {
                _services.Add(service);
            }

            _services.AddSingleton <IQQContext>(this);

            // 模块
            _services.AddSingleton <ILoginModule, LoginModule>();
            _services.AddSingleton <IChatModule, ChatModule>();
            _services.AddSingleton <StoreModule>();
            _services.AddSingleton <SessionModule>();

            // 服务
            _services.AddSingleton <IHttpService, HttpService>();
            _services.AddSingleton <IQQActionFactory, QQActionFactory>();

            configureServices?.Invoke(_services);
            _serviceProvider = _services.BuildServiceProvider();

            _notifyListener = GetSerivce <QQNotifyEventListener>();
            _logger         = GetSerivce <ILogger>();
        }
Exemplo n.º 2
0
 /// <summary>
 /// 构造方法,初始化模块和服务
 /// </summary>
 public WebQQClient(Func <IQQContext, ILogger> loggerFunc, QQNotifyEventListener notifyListener) : this(m =>
 {
     if (loggerFunc != null)
     {
         m.AddSingleton <ILogger>(p => loggerFunc(p.GetRequiredService <IQQContext>()));
     }
     if (notifyListener != null)
     {
         m.AddSingleton(notifyListener);
     }
 })
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// 构造方法,初始化模块和服务
 /// </summary>
 public WebQQClient(ILogger logger = null, QQNotifyEventListener notifyListener = null) : this(m =>
 {
     if (logger != null)
     {
         m.AddSingleton(logger);
     }
     if (notifyListener != null)
     {
         m.AddSingleton(notifyListener);
     }
 })
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// 构造方法,初始化模块和服务
        /// </summary>
        public WebQQClient(QQNotifyEventListener notifyListener = null)
        {
            _services = new ServiceCollection();
            Startup.ConfigureServices(_services);

            _services.AddSingleton <IQQContext>(this);

            // 模块
            _services.AddSingleton <ILoginModule, LoginModule>();
            _services.AddSingleton <StoreModule>();
            _services.AddSingleton <SessionModule>();

            // 服务
            _services.AddSingleton <IHttpService, QQHttp>();
            _services.AddSingleton <ILogger>(new QQLogger(this, LogLevel.Debug));
            _services.AddSingleton <IQQActionFactory, QQActionFactory>();

            _serviceProvider = _services.BuildServiceProvider();
            Startup.Configure(_serviceProvider);

            _notifyListener = notifyListener;
            _logger         = GetSerivce <ILogger>();
        }