public static IServiceCollection AddMoodleIntegration <TIntegrator, TFactory>( this IServiceCollection services, Action <MoodleIntegrationBuilder> builder) where TIntegrator : class, IMoodleIntegrator where TFactory : class, IMoodleRequestFactory { var configuration = new MoodleIntegrationBuilder(); builder(configuration); var moodleRequestFactoryConfig = new MoodleRequestFactoryConfiguration { RestFormat = configuration.RestFormat, Token = configuration.Token }; var moodleIntegratorConfig = new MoodleIntegratorConfiguration { MoodleRestUrl = configuration.RestUrl }; services.AddScoped(_ => moodleRequestFactoryConfig); services.AddScoped <IMoodleRequestFactory, TFactory>(); services.AddScoped(_ => moodleIntegratorConfig); services.AddScoped <IMoodleIntegrator, MoodleIntegrator>(); return(services); }
public MoodleRequestFactory(MoodleRequestFactoryConfiguration config) { _token = config.Token; _restFormat = config.RestFormat; }