diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 95c709ce1..f472cdd8f 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -20,7 +20,6 @@ using Discord.Net; using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Common.Configs; using NadekoBot.Db; -using NadekoBot.Modules.Gambling.Services; using Serilog; namespace NadekoBot @@ -108,17 +107,15 @@ namespace NadekoBot .AddRedis(_creds.RedisOptions) // redis .AddSingleton(Client) // discord socket client .AddSingleton(_commandService) - .AddSingleton(this) // pepega + .AddSingleton(this) .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddBotStringsServices() .AddConfigServices() - .AddConfigMigrators() // todo remove config migrators + .AddConfigMigrators() .AddMemoryCache() - .AddSingleton() - .AddSingleton() // music .AddMusic() ; @@ -142,31 +139,18 @@ namespace NadekoBot // todo no public bot attribute svcs.Scan(scan => scan .FromAssemblyOf() - .AddClasses(classes => classes.AssignableTo()) - .AsSelf() - .AsImplementedInterfaces() - .WithSingletonLifetime() - - // behaviours .AddClasses(classes => classes.AssignableToAny( + // services + typeof(INService), + + // behaviours typeof(IEarlyBehavior), typeof(ILateBlocker), typeof(IInputTransformer), typeof(ILateExecutor))) - .AsSelf() - .AsImplementedInterfaces() - .WithSingletonLifetime() - - // services - .AddClasses(classes => classes.AssignableTo()) - .AsImplementedInterfaces() - .AsSelf() + .AsSelfWithInterfaces() .WithSingletonLifetime() ); - - // svcs.AddSingleton(x => x.GetService()); - // svcs.AddSingleton(x => x.GetService()); - // svcs.AddSingleton(x => x.GetService()); //initialize Services Services = svcs.BuildServiceProvider(); @@ -320,15 +304,14 @@ namespace NadekoBot sw.Stop(); Log.Information("Shard {ShardId} connected in {Elapsed:F2}s", Client.ShardId, sw.Elapsed.TotalSeconds); - var stats = Services.GetService(); + var stats = Services.GetRequiredService(); stats.Initialize(); - var commandHandler = Services.GetService(); - var CommandService = Services.GetService(); + var commandHandler = Services.GetRequiredService(); // start handling messages received in commandhandler await commandHandler.StartHandling().ConfigureAwait(false); - _ = await CommandService.AddModulesAsync(this.GetType().GetTypeInfo().Assembly, Services) + _ = await _commandService.AddModulesAsync(this.GetType().GetTypeInfo().Assembly, Services) .ConfigureAwait(false); HandleStatusChanges(); diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index c300e0633..9cebb96b4 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -1,4 +1,5 @@ -using Discord; +using System; +using Discord; using Discord.Commands; using Discord.WebSocket; using Microsoft.EntityFrameworkCore; diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index 0ea05e644..0a5fcb7c8 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -18,7 +18,7 @@ using Serilog; namespace NadekoBot.Modules.Administration.Services { - public sealed class SelfService : ILateExecutor, IReadyExecutor + public sealed class SelfService : ILateExecutor, IReadyExecutor, INService { private readonly ConnectionMultiplexer _redis; private readonly CommandHandler _cmdHandler; @@ -54,7 +54,6 @@ namespace NadekoBot.Modules.Administration.Services _httpFactory = factory; _bss = bss; - Log.Information("Self service created"); var sub = _redis.GetSubscriber(); if (_client.ShardId == 0) { diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index 0f6266085..f0b55b1f7 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -77,7 +77,6 @@ namespace NadekoBot.Modules.CustomReactions.Services _pubSub = pubSub; _rng = new NadekoRandom(); - Log.Information("Custom reaction service created"); _pubSub.Sub(_crsReloadedKey, OnCrsShouldReload); pubSub.Sub(_gcrAddedKey, OnGcrAdded); pubSub.Sub(_gcrDeletedkey, OnGcrDeleted); diff --git a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs index 5d86bccaa..49fa41fca 100644 --- a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs @@ -11,7 +11,7 @@ using NadekoBot.Modules.Administration; namespace NadekoBot.Modules.Gambling.Services { - public class ShopService : IShopService + public class ShopService : IShopService, INService { private readonly DbService _db; diff --git a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs index c915b4d39..6e528f81a 100644 --- a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs @@ -20,7 +20,7 @@ using Serilog; namespace NadekoBot.Modules.Utility.Services { - public sealed class RepeaterService : IReadyExecutor + public sealed class RepeaterService : IReadyExecutor, INService { public const int MAX_REPEATERS = 5; diff --git a/src/NadekoBot/Services/ICurrencyService.cs b/src/NadekoBot/Services/ICurrencyService.cs index 07c732b29..b76897315 100644 --- a/src/NadekoBot/Services/ICurrencyService.cs +++ b/src/NadekoBot/Services/ICurrencyService.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace NadekoBot.Services { - public interface ICurrencyService : INService + public interface ICurrencyService { Task AddAsync(ulong userId, string reason, long amount, bool gamble = false); Task AddAsync(IUser user, string reason, long amount, bool sendMessage = false, bool gamble = false); diff --git a/src/NadekoBot/Services/ILocalization.cs b/src/NadekoBot/Services/ILocalization.cs index c3cfbe94f..b9fa898d6 100644 --- a/src/NadekoBot/Services/ILocalization.cs +++ b/src/NadekoBot/Services/ILocalization.cs @@ -4,7 +4,7 @@ using Discord; namespace NadekoBot.Services { - public interface ILocalization : INService + public interface ILocalization { CultureInfo DefaultCultureInfo { get; } ConcurrentDictionary GuildCultureInfos { get; } diff --git a/src/NadekoBot/Services/IStatsService.cs b/src/NadekoBot/Services/IStatsService.cs index b47724fb7..797505274 100644 --- a/src/NadekoBot/Services/IStatsService.cs +++ b/src/NadekoBot/Services/IStatsService.cs @@ -2,7 +2,7 @@ namespace NadekoBot.Services { - public interface IStatsService : INService + public interface IStatsService { string Author { get; } long CommandsRan { get; } diff --git a/src/NadekoBot/Services/Impl/BehaviorExecutor.cs b/src/NadekoBot/Services/Impl/BehaviorExecutor.cs index a560a2fcf..6444e9724 100644 --- a/src/NadekoBot/Services/Impl/BehaviorExecutor.cs +++ b/src/NadekoBot/Services/Impl/BehaviorExecutor.cs @@ -11,7 +11,7 @@ using Microsoft.Extensions.DependencyInjection; namespace NadekoBot.Services { - public sealed class BehaviorExecutor : IBehaviourExecutor + public sealed class BehaviorExecutor : IBehaviourExecutor, INService { private readonly IServiceProvider _services; private IEnumerable _lateExecutors; diff --git a/src/NadekoBot/Services/Impl/CurrencyService.cs b/src/NadekoBot/Services/Impl/CurrencyService.cs index 5df75749a..35a95bf81 100644 --- a/src/NadekoBot/Services/Impl/CurrencyService.cs +++ b/src/NadekoBot/Services/Impl/CurrencyService.cs @@ -12,7 +12,7 @@ using NadekoBot.Modules.Gambling.Services; namespace NadekoBot.Services { - public class CurrencyService : ICurrencyService + public class CurrencyService : ICurrencyService, INService { private readonly DbService _db; private readonly GamblingConfigService _gss; diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index a4d69cb33..eac1dc05c 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -18,7 +18,7 @@ using Serilog; namespace NadekoBot.Services { - public class GoogleApiService : IGoogleApiService + public class GoogleApiService : IGoogleApiService, INService { private const string SearchEngineId = "018084019232060951019:hs5piey28-e"; diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index 15dd00d8f..7381d0c6b 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -11,7 +11,7 @@ using NadekoBot.Modules.Administration; namespace NadekoBot.Services { - public class Localization : ILocalization + public class Localization : ILocalization, INService { private readonly BotConfigService _bss; private readonly DbService _db; diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 46d170585..715aac1bb 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -12,7 +12,7 @@ using Serilog; namespace NadekoBot.Services { - public class StatsService : IStatsService + public class StatsService : IStatsService, INService { private readonly DiscordSocketClient _client; private readonly IBotCredentials _creds;