fix: create-config autofac registration

Can now use the create-config subcommand without autofac throwing an
exception
recyclarr
Robert Dailey 3 years ago
parent be0c2e23db
commit 008adedf9d

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Fix exception that occurred when running the create-config subcommand.
## [1.3.1] - 2021-05-05
### Changed

@ -0,0 +1,40 @@
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using Autofac;
using CliFx;
using NUnit.Framework;
namespace Trash.Tests
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CompositionRootTest
{
private class ConcreteTypeEnumerator<T> : IEnumerable
{
private readonly Assembly _asm;
public ConcreteTypeEnumerator()
{
_asm = Assembly.GetAssembly(typeof(CompositionRoot)) ?? throw new NullReferenceException();
}
public IEnumerator GetEnumerator()
{
return _asm.DefinedTypes
.Where(t => t.GetInterfaces().Contains(typeof(ICommand)) && !t.IsAbstract)
.GetEnumerator();
}
}
[TestCaseSource(typeof(ConcreteTypeEnumerator<ICommand>))]
public void Resolve_ICommandConcreteClasses(Type concreteCmd)
{
var builder = new ContainerBuilder();
var container = CompositionRoot.Setup(builder);
container.Resolve(concreteCmd);
}
}
}

@ -67,9 +67,7 @@ namespace Trash
{
// Register all types deriving from CliFx's ICommand. These are all of our supported subcommands.
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.IsAssignableTo(typeof(ICommand)))
.As<IServiceCommand>()
.AsSelf();
.Where(t => t.IsAssignableTo(typeof(ICommand)));
// Used to access the chosen command class. This is assigned from CliTypeActivator
builder.RegisterType<ActiveServiceCommandProvider>()

Loading…
Cancel
Save