Skip to content

Commit

Permalink
refactor: Add implementations of IEntityTypeConfigurator to the servi…
Browse files Browse the repository at this point in the history
…ce collection

This change was made so that implementations of IEntityTypeConfigurator can have their own dependencies injected into their constructor.
  • Loading branch information
MrDave1999 committed Mar 20, 2024
1 parent 3bf9aa0 commit d89dde8
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/HostApplication/PluginStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

public static class PluginStartup
{
/// <summary>
/// Configures the plugins.
/// </summary>
public static void Configure(WebApplicationBuilder builder)
public static void ConfigureServices(WebApplicationBuilder builder)
{
var envConfiguration = new CPluginEnvConfiguration();
PluginLoader.Load(envConfiguration);
var dependencyServicesRegisterers = TypeFinder.FindSubtypesOf<IDependencyServicesRegisterer>();
foreach (var dependencyServicesRegisterer in dependencyServicesRegisterers)
dependencyServicesRegisterer.RegisterServices(builder.Services, builder.Configuration);

var entityTypeConfigurators = TypeFinder
.FindSubtypesOf<IEntityTypeConfigurator>()
.ToList();

builder
.Services
.AddSingleton<IEnumerable<IEntityTypeConfigurator>>(entityTypeConfigurators);
.AddSubtypesOf<IEntityTypeConfigurator>(ServiceLifetime.Transient);

// These services are only added when no plug-in registers its own implementation.
// These services are only added when no plugin registers its own implementation.
builder.Services.TryAddSingleton<IEmailService, FakeEmailService>();
builder.Services.TryAddSingleton<IInstantMessaging, FakeInstantMessaging>();
}
Expand Down

0 comments on commit d89dde8

Please sign in to comment.