diff --git a/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj b/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj index 53790f9..8af57e2 100644 --- a/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj +++ b/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj @@ -15,7 +15,7 @@ True LICENSE README.md - 1.0.7 + 1.0.8 diff --git a/Telegrator.Hosting/HostedTelegramBotInfo.cs b/Telegrator.Hosting/HostedTelegramBotInfo.cs index a8c3ecb..5c48553 100644 --- a/Telegrator.Hosting/HostedTelegramBotInfo.cs +++ b/Telegrator.Hosting/HostedTelegramBotInfo.cs @@ -5,13 +5,26 @@ using Telegrator.Configuration; namespace Telegrator.Hosting { + /// + /// Implementation of that provides bot information. + /// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities + /// + /// + /// + /// public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfigurationManager configuration) : ITelegramBotInfo { /// public User User { get; } = client.GetMe().Result; + /// + /// Provides access to services of this Hosted telegram bot + /// public IServiceProvider Services { get; } = services; + /// + /// Provides access to configuration of this Hosted telegram bot + /// public IConfigurationManager Configuration { get; } = configuration; } } diff --git a/Telegrator.Hosting/Telegrator.Hosting.csproj b/Telegrator.Hosting/Telegrator.Hosting.csproj index 19ace06..d46d425 100644 --- a/Telegrator.Hosting/Telegrator.Hosting.csproj +++ b/Telegrator.Hosting/Telegrator.Hosting.csproj @@ -16,7 +16,7 @@ True LICENSE README.md - 1.0.7 + 1.0.8 diff --git a/Telegrator/Alligator.cs b/Telegrator/Alligator.cs index 6f0cc30..b3407bc 100644 --- a/Telegrator/Alligator.cs +++ b/Telegrator/Alligator.cs @@ -8,12 +8,12 @@ namespace Telegrator public static class Alligator { /// - /// Gets or sets flags of what debug messages to write + /// Gets or sets flags of what trace messages to write /// public static DebugLevel Allowed { get; set; } = DebugLevel.None; /// - /// Writes debug message if Indent level has Router flag + /// Writes trace message if Indent level has Router flag /// /// public static void RouterWriteLine(string message) @@ -34,7 +34,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Providers flag + /// Writes trace message if Indent level has Providers flag /// /// public static void ProviderWriteLine(string message) @@ -44,7 +44,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Providers flag + /// Writes trace message if Indent level has Providers flag /// /// /// @@ -55,7 +55,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Filters flag + /// Writes trace message if Indent level has Filters flag /// /// public static void FilterWriteLine(string message) @@ -65,7 +65,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Filters flag + /// Writes trace message if Indent level has Filters flag /// /// /// @@ -76,7 +76,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Pool flag + /// Writes trace message if Indent level has Pool flag /// /// public static void PoolWriteLine(string message) @@ -86,7 +86,7 @@ namespace Telegrator } /// - /// Writes debug message if Indent level has Pool flag + /// Writes trace message if Indent level has Pool flag /// /// /// @@ -95,13 +95,24 @@ namespace Telegrator if (Allowed.HasFlag(DebugLevel.HandlersPool)) Trace.WriteLine(string.Format(message, args)); } - + + /// + /// Writes trace message if flag was set + /// + /// + /// public static void WriteLine(DebugLevel level, string message) { if (Allowed.HasFlag(level)) Trace.WriteLine(message); } + /// + /// Writes trace message if flag was set + /// + /// + /// + /// public static void WriteLine(DebugLevel level, string message, params object[] args) { if (Allowed.HasFlag(level)) diff --git a/Telegrator/MadiatorCore/Descriptors/DefaultCustomDescriptors.cs b/Telegrator/MadiatorCore/Descriptors/DefaultCustomDescriptors.cs index d4728e8..c9a8a5f 100644 --- a/Telegrator/MadiatorCore/Descriptors/DefaultCustomDescriptors.cs +++ b/Telegrator/MadiatorCore/Descriptors/DefaultCustomDescriptors.cs @@ -9,8 +9,16 @@ using Telegrator.Handlers.Components; namespace Telegrator.MadiatorCore.Descriptors { + /// + /// Descriptor for creating handlers from methods + /// + /// public class MethodHandlerDescriptor : HandlerDescriptor where TUpdate : class { + /// + /// Initializes new instance of + /// + /// public MethodHandlerDescriptor(AbstractHandlerAction action) : base(DescriptorType.General) { UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method); diff --git a/Telegrator/MadiatorCore/Descriptors/HandlerDescriptor.cs b/Telegrator/MadiatorCore/Descriptors/HandlerDescriptor.cs index e582cea..fe5c164 100644 --- a/Telegrator/MadiatorCore/Descriptors/HandlerDescriptor.cs +++ b/Telegrator/MadiatorCore/Descriptors/HandlerDescriptor.cs @@ -420,6 +420,12 @@ namespace Telegrator.MadiatorCore.Descriptors InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); } + /// + /// Sets singleton instance of this descriptor + /// Throws exception if instance already set + /// + /// + /// public void SetInstance(UpdateHandlerBase instance) { if (SingletonInstance != null) @@ -428,6 +434,20 @@ namespace Telegrator.MadiatorCore.Descriptors SingletonInstance = instance; } + /// + /// Tries to set singleton instance of this descriptor + /// + /// + /// + public bool TrySetInstance(UpdateHandlerBase instance) + { + if (SingletonInstance != null) + return false; + + SingletonInstance = instance; + return true; + } + /// public override string ToString() => DisplayString ?? HandlerType.Name; diff --git a/Telegrator/Providers/HandlersProvider.cs b/Telegrator/Providers/HandlersProvider.cs index 46d5e6e..bcc8e80 100644 --- a/Telegrator/Providers/HandlersProvider.cs +++ b/Telegrator/Providers/HandlersProvider.cs @@ -70,7 +70,9 @@ namespace Telegrator.Providers return descriptor.SingletonInstance; UpdateHandlerBase instance = GetHandlerInstanceInternal(descriptor); - descriptor.SingletonInstance = useSingleton ? instance : null; + if (useSingleton) + descriptor.TrySetInstance(instance); + descriptor.LazyInitialization?.Invoke(instance); return instance; } diff --git a/Telegrator/Telegrator.csproj b/Telegrator/Telegrator.csproj index 907f6fc..f3490e8 100644 --- a/Telegrator/Telegrator.csproj +++ b/Telegrator/Telegrator.csproj @@ -17,7 +17,7 @@ True True LICENSE - 1.0.7 + 1.0.8