private void AddServices() { var startingGuildIdList = Client.Guilds.Select(x => (long)x.Id).ToList(); //this unit of work will be used for initialization of all modules too, to prevent multiple queries from running using (var uow = _db.UnitOfWork) { AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray(); IBotConfigProvider botConfigProvider = new BotConfigProvider(_db, _botConfig, Cache); //initialize Services Services = new NServiceProvider() .AddManual <IBotCredentials>(Credentials) .AddManual(_db) .AddManual(Client) .AddManual(CommandService) .AddManual(botConfigProvider) .AddManual <NadekoBot>(this) .AddManual <IUnitOfWork>(uow) .AddManual <IDataCache>(Cache); Services.LoadFrom(Assembly.GetAssembly(typeof(CommandHandler))); var commandHandler = Services.GetService <CommandHandler>(); commandHandler.AddServices(Services); LoadTypeReaders(typeof(NadekoBot).Assembly); } Services.Unload(typeof(IUnitOfWork)); // unload it after the startup }
protected StateController() : base() { try { if (EcpState.IsLogin() != true) { IIdentityServer server = NServiceProvider.GetService <IIdentityServer>(); string auth = HttpContextProvider.Current.Request.Headers["Authorization"]; EcpState state = server.InspurIdSSO(auth).Result; EcpState.SetCurrent(state); } } catch (Exception ex) { throw new ForbidException(ex.Message, ex); } }