Testing Serverless Applications - Part 1
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
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