public WebWeChatClient(Action <IServiceCollection> configureServices = null) { _services = new ServiceCollection(); foreach (var service in CommonServices) { _services.Add(service); } _services.AddSingleton <IWeChatContext>(this); // 模块 _services.AddSingleton <ILoginModule, LoginModule>(); _services.AddSingleton <IContactModule, ContactModule>(); _services.AddSingleton <IChatModule, ChatModule>(); _services.AddSingleton <StoreModule>(); _services.AddSingleton <SessionModule>(); // 服务 _services.AddSingleton <IHttpService, HttpService>(); _services.AddSingleton <IWeChatActionFactory, WeChatActionFactory>(); configureServices?.Invoke(_services); _serviceProvider = _services.BuildServiceProvider(); _notifyListener = GetSerivce <WeChatNotifyEventListener>(); _logger = GetSerivce <ILogger>(); }
public WebWeChatClient(WeChatNotifyEventListener notifyListener = null) { _services = new ServiceCollection(); Startup.ConfigureServices(_services); _services.AddSingleton <IWeChatContext>(this); // 模块 _services.AddSingleton <ILoginModule, LoginModule>(); _services.AddSingleton <IContactModule, ContactModule>(); _services.AddSingleton <IChatModule, ChatModule>(); _services.AddSingleton <StoreModule>(); _services.AddSingleton <SessionModule>(); // 服务 _services.AddSingleton <IHttpService, WeChatHttp>(); _services.AddSingleton <ILogger>(provider => new WeChatLogger(this, LogLevel.Information)); _services.AddSingleton <IWeChatActionFactory, WeChatActionFactory>(); _serviceProvider = _services.BuildServiceProvider(); Startup.Configure(_serviceProvider); _notifyListener = notifyListener; _logger = GetSerivce <ILogger>(); }
/// <summary> /// 构造方法,初始化模块和服务 /// </summary> public WebWeChatClient(Func <IWeChatContext, ILogger> loggerFunc, WeChatNotifyEventListener notifyListener) : this(m => { if (loggerFunc != null) { m.AddSingleton <ILogger>(p => loggerFunc(p.GetRequiredService <IWeChatContext>())); } if (notifyListener != null) { m.AddSingleton(notifyListener); } }) { }
/// <summary> /// 构造方法,初始化模块和服务 /// </summary> public WebWeChatClient(ILogger logger, WeChatNotifyEventListener notifyListener) : this(m => { if (logger != null) { m.AddSingleton(logger); } if (notifyListener != null) { m.AddSingleton(notifyListener); } }) { }