Adding full DI navigation example for testing purposes.
- adding internal private field into FormBase class - adding Extension methods into DependencyInjection namespace for use - adding 2 NavigateTo extension methods for DI using ServiceProvider - adding example project - adding to readme as example
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TelegramBotBase.DependencyInjection;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
@@ -16,14 +17,19 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
||||
{
|
||||
throw new ArgumentException($"{nameof(startFormClass)} argument must be a {nameof(FormBase)} type");
|
||||
}
|
||||
|
||||
|
||||
_startFormClass = startFormClass;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public FormBase CreateForm()
|
||||
{
|
||||
return (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
|
||||
//Sets an internal field for future ServiceProvider navigation
|
||||
fb.SetServiceProvider(_serviceProvider);
|
||||
|
||||
return fb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user