naps2/NAPS2.Lib/AutofacOperationFactory.cs
Ben Olden-Cooligan 35669502cc Migrate from Ninject to Autofac
Performance is much better (might save ~20ms on startup), plus more popular in general means potentially easier for others to contribute/use the code.
2022-10-30 18:14:42 -07:00

22 lines
585 B
C#

using Autofac;
namespace NAPS2;
public class AutofacOperationFactory : IOperationFactory
{
private readonly IComponentContext _container;
private readonly ErrorOutput _errorOutput;
public AutofacOperationFactory(IComponentContext container, ErrorOutput errorOutput)
{
_container = container;
_errorOutput = errorOutput;
}
public T Create<T>() where T : IOperation
{
var op = _container.Resolve<T>();
op.Error += (sender, args) => _errorOutput.DisplayError(args.ErrorMessage, args.Exception);
return op;
}
}