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 static class IServiceCollectionExtensions | |
{ | |
public static IServiceCollection ConnectImplementations<TService>(this IServiceCollection services, Assembly assembly)where TService : class | |
{ | |
return services.ConnectImplementations(typeof (TService), assembly); | |
} | |
public static IServiceCollection ConnectImplementations(this IServiceCollection services, Type serviceType, Assembly assembly) | |
{ | |
if (!serviceType.IsInterface) throw new ArgumentException($"{nameof(serviceType)} must be an interface"); |
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 class CharacterController : Controller | |
{ | |
/*[...]*/ | |
public IActionResult Profile(int id) | |
{ | |
/*[...]*/ | |
var viewModel = viewFactory.Build<int, CharacterProfileViewModelBuilder>(id); | |
return View(viewModel); | |
} | |
} |
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 class FooController : Controller | |
{ | |
private readonly IViewFactory viewFactory; | |
public FooController(IViewFactory viewFactory) { this.viewFactory = viewFactory; } | |
public IActionResult Index() | |
{ | |
var viewModel = viewFactory.Create<CreateFooViewModel>(); | |
NewerOlder