Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created July 19, 2017 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/ad11d9188b8ddc467d50b4efa2458b48 to your computer and use it in GitHub Desktop.
Save justinyoo/ad11d9188b8ddc467d50b4efa2458b48 to your computer and use it in GitHub Desktop.
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