-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure registrations using modules and build separate container …
…to resolve config
- Loading branch information
Showing
4 changed files
with
114 additions
and
81 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Mutagen.Bethesda.Analyzers.Cli/Modules/AnalyzerCommandModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Autofac; | ||
using Mutagen.Bethesda.Analyzers.Cli.Args; | ||
using Mutagen.Bethesda.Analyzers.Cli.Overrides; | ||
using Mutagen.Bethesda.Analyzers.Reporting.Handlers; | ||
using Mutagen.Bethesda.Environments.DI; | ||
using Mutagen.Bethesda.Plugins.Order.DI; | ||
using Noggog.WorkEngine; | ||
|
||
namespace Mutagen.Bethesda.Analyzers.Cli.Modules; | ||
|
||
public class AnalyzerCommandModule(RunAnalyzersCommand command) : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterInstance(command).AsImplementedInterfaces(); | ||
builder.RegisterInstance(new GameReleaseInjection(command.GameRelease)).AsImplementedInterfaces(); | ||
builder.RegisterInstance(new NumWorkThreadsConstant(command.NumThreads)).AsImplementedInterfaces(); | ||
|
||
if (command.OutputFilePath is not null) | ||
{ | ||
builder.RegisterType<CsvReportHandler>().AsImplementedInterfaces().SingleInstance(); | ||
builder.RegisterInstance(new CsvInputs(command.OutputFilePath)).AsSelf().AsImplementedInterfaces(); | ||
} | ||
|
||
if (command.CustomDataFolder is not null) | ||
{ | ||
var dataDirectoryProvider = new DataDirectoryInjection(command.CustomDataFolder); | ||
builder.RegisterInstance(dataDirectoryProvider).As<IDataDirectoryProvider>(); | ||
} | ||
|
||
if (command.UseDataFolderForLoadOrder) | ||
{ | ||
builder.RegisterType<DataDirectoryEnabledPluginListingsProvider>().As<IEnabledPluginListingsProvider>(); | ||
builder.RegisterType<NullPluginListingsPathProvider>().As<IPluginListingsPathProvider>(); | ||
builder.RegisterType<NullCreationClubListingsPathProvider>().As<ICreationClubListingsPathProvider>(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
Mutagen.Bethesda.Analyzers.Cli/Modules/AnalyzerConfigModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.IO.Abstractions; | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Mutagen.Bethesda.Analyzers.Autofac; | ||
using Mutagen.Bethesda.Analyzers.Cli.Overrides; | ||
using Mutagen.Bethesda.Analyzers.Config.Analyzer; | ||
using Mutagen.Bethesda.Analyzers.Reporting.Handlers; | ||
using Mutagen.Bethesda.Environments.DI; | ||
using Mutagen.Bethesda.Plugins.Order.DI; | ||
|
||
namespace Mutagen.Bethesda.Analyzers.Cli.Modules; | ||
|
||
public class AnalyzerConfigModule(GameRelease gameRelease) : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
var analyzerConfig = GetAnalyzerConfig(); | ||
|
||
if (analyzerConfig.DataDirectoryPath.HasValue) | ||
{ | ||
var dataDirectoryProvider = new DataDirectoryInjection(analyzerConfig.DataDirectoryPath.Value); | ||
builder.RegisterInstance(dataDirectoryProvider).As<IDataDirectoryProvider>(); | ||
} | ||
|
||
if (analyzerConfig.LoadOrderSetByDataDirectory) | ||
{ | ||
builder.RegisterType<DataDirectoryEnabledPluginListingsProvider>().As<IEnabledPluginListingsProvider>(); | ||
builder.RegisterType<NullPluginListingsPathProvider>().As<IPluginListingsPathProvider>(); | ||
builder.RegisterType<NullCreationClubListingsPathProvider>().As<ICreationClubListingsPathProvider>(); | ||
} | ||
else if (analyzerConfig.LoadOrderSetToMods is not null) | ||
{ | ||
builder.RegisterInstance(new InjectedEnabledPluginListingsProvider(analyzerConfig.LoadOrderSetToMods)).As<IEnabledPluginListingsProvider>(); | ||
builder.RegisterType<NullPluginListingsPathProvider>().As<IPluginListingsPathProvider>(); | ||
builder.RegisterType<NullCreationClubListingsPathProvider>().As<ICreationClubListingsPathProvider>(); | ||
} | ||
|
||
if (analyzerConfig.OutputFilePath is not null) | ||
{ | ||
builder.RegisterType<CsvReportHandler>().AsImplementedInterfaces().SingleInstance(); | ||
builder.RegisterInstance(new CsvInputs(analyzerConfig.OutputFilePath)).AsSelf().AsImplementedInterfaces(); | ||
} | ||
} | ||
|
||
private IAnalyzerConfigLookup GetAnalyzerConfig() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddLogging(x => x.AddConsole()); | ||
|
||
var builder = new ContainerBuilder(); | ||
builder.Populate(services); | ||
builder.RegisterInstance(new FileSystem()).As<IFileSystem>(); | ||
builder.RegisterModule<MainModule>(); | ||
builder.RegisterInstance(new GameReleaseInjection(gameRelease)) | ||
.AsImplementedInterfaces(); | ||
|
||
var container = builder.Build(); | ||
|
||
var analyzerConfigProvider = container.Resolve<AnalyzerConfigProvider>(); | ||
return analyzerConfigProvider.Config; | ||
} | ||
} |
13 changes: 3 additions & 10 deletions
13
Mutagen.Bethesda.Analyzers.Cli/Modules/RunAnalyzerModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
using Autofac; | ||
using Mutagen.Bethesda.Analyzers.Autofac; | ||
using Mutagen.Bethesda.Analyzers.Cli.Args; | ||
using Mutagen.Bethesda.Analyzers.Reporting.Drops; | ||
using Mutagen.Bethesda.Analyzers.Reporting.Handlers; | ||
using Mutagen.Bethesda.Analyzers.SDK.Drops; | ||
|
||
namespace Mutagen.Bethesda.Analyzers.Cli.Modules; | ||
|
||
public class RunAnalyzerModule(RunAnalyzersCommand? command) : Module | ||
public class RunAnalyzerModule : Module | ||
{ | ||
public RunAnalyzerModule() : this(null) {} | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
if (command?.OutputFilePath is not null) | ||
{ | ||
builder.RegisterType<CsvReportHandler>().AsImplementedInterfaces(); | ||
builder.RegisterInstance(new CsvInputs(command.OutputFilePath)).AsSelf().AsImplementedInterfaces(); | ||
} | ||
|
||
// Last registered runs first | ||
builder.RegisterType<PassToHandlerReportDropbox>().AsImplementedInterfaces(); | ||
builder.RegisterDecorator<EditorIdEnricher, IReportDropbox>(); | ||
builder.RegisterDecorator<MinimumSeverityFilter, IReportDropbox>(); | ||
builder.RegisterDecorator<SeverityAdjuster, IReportDropbox>(); | ||
builder.RegisterDecorator<DisallowedParametersChecker, IReportDropbox>(); | ||
|
||
builder.RegisterType<ConsoleReportHandler>().AsImplementedInterfaces(); | ||
|
||
builder.RegisterModule<MainModule>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters