Last active
May 10, 2018 05:57
-
-
Save memark/3718c5a3297b85e93b200bc9dbe4e63e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static void RegisterBusinessLogicStubs(ContainerBuilder containerBuilder) | |
{ | |
var tempContainer = CreateBusinessLogicAutofacModuleContainer(); | |
var interfaceToStubList = GetInterfaceTypeList(tempContainer); | |
var stubList = interfaceToStubList.Select(x => Substitute.For(new[] { x }, new object[] { })); | |
foreach (var s in stubList) | |
containerBuilder.RegisterInstance(s).AsImplementedInterfaces(); | |
} | |
private static IContainer CreateBusinessLogicAutofacModuleContainer() | |
{ | |
var containerBuilder = new ContainerBuilder(); | |
var module = BusinessLogicAutofacModule.CreateWithoutDatabaseDefaults(default, default, default, default, default, default, default, default); | |
containerBuilder.RegisterModule(module); | |
return containerBuilder.Build(); | |
} | |
private static IEnumerable<Type> GetInterfaceTypeList(IContainer container) => | |
container.ComponentRegistry.Registrations | |
.SelectMany(x => x.Services) | |
.OfType<IServiceWithType>() | |
.Select(x => x.ServiceType) | |
.Where(x => x.IsInterface); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment