Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Testing Serverless Applications - Part 1
public interface IServiceLocatorBuilder : IDisposable
{
IServiceLocator Build();
IServiceLocatorBuilder RegisterModule<TModule>(RegistrationHandler handler = null) where TModule : IModule, new();
}
public class ServiceLocatorBuilder : IServiceLocatorBuilder
{
private ContainerBuilder _containerBuilder;
public ServiceLocatorBuilder()
{
this._containerBuilder = new ContainerBuilder();
}
public IServiceLocator Build()
{
var container = this._containerBuilder.Build();
return new AutofacServiceLocator(container);
}
public IServiceLocatorBuilder RegisterModule<TModule>(RegistrationHandler handler = null) where TModule : IModule, new()
{
this._containerBuilder.RegisterModule<TModule>();
if (handler.IsNullOrDefault())
{
return this;
}
if (handler.RegisterTypeAsInstancePerDependency.IsNullOrDefault())
{
return this;
}
handler.RegisterTypeAsInstancePerDependency.Invoke(this._containerBuilder);
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment