Adding a exception for invalid ServiceProviders #62
- adding an internal exception handler to catch InvalidOperationException and throw a new explicit one
This commit is contained in:
parent
6e7acdbdba
commit
b829f43c5d
@ -8,6 +8,7 @@ using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Sessions;
|
||||
using Console = TelegramBotBase.Tools.Console;
|
||||
@ -139,6 +140,13 @@ public sealed class BotBase
|
||||
mr.IsFirstHandler = false;
|
||||
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
||||
}
|
||||
catch (InvalidServiceProviderConfiguration ex)
|
||||
{
|
||||
var ds = Sessions.GetSession(e.DeviceId);
|
||||
OnException(new SystemExceptionEventArgs(e.Message.Text, e.DeviceId, ds, ex));
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var ds = Sessions.GetSession(e.DeviceId);
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace TelegramBotBase.Exceptions
|
||||
{
|
||||
public sealed class InvalidServiceProviderConfiguration : Exception
|
||||
{
|
||||
public InvalidServiceProviderConfiguration(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TelegramBotBase.DependencyInjection;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
@ -24,7 +25,16 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
||||
|
||||
public FormBase CreateForm()
|
||||
{
|
||||
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
FormBase fb = null;
|
||||
|
||||
try
|
||||
{
|
||||
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
}
|
||||
catch(InvalidOperationException ex)
|
||||
{
|
||||
throw new InvalidServiceProviderConfiguration(ex.Message, ex);
|
||||
}
|
||||
|
||||
//Sets an internal field for future ServiceProvider navigation
|
||||
fb.SetServiceProvider(_serviceProvider);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user