Skip to content

Instantly share code, notes, and snippets.

@Manu06D
Created August 2, 2020 18:51
Show Gist options
  • Save Manu06D/33388cdf2d84c720d420780bb5615002 to your computer and use it in GitHub Desktop.
Save Manu06D/33388cdf2d84c720d420780bb5615002 to your computer and use it in GitHub Desktop.
var services = new ServiceCollection();
Assembly[] assembliesToScan = new Assembly[]{
AppFramework.Core.AppFrameworkCore.Assembly,
Core.CarCatalogCore.Assembly,
AppFrameworkModels.Assembly
};
services.AddMediatR(assembliesToScan);
services.AddAutoMapper(new Assembly[] {
AppFramework.Core.AppFrameworkCore.Assembly, //Automatic IMapFrom mapping
Assembly.GetExecutingAssembly() //Custom Mapping
});
builder.Populate(services);
builder.RegisterModule(new RegisterAutofacModule() { Assemblies = assembliesToScan });
builder.RegisterAssemblyTypes(CarCatalogModels.Assembly).Where(t => t.IsClosedTypeOf(typeof(IValidator<>))).AsImplementedInterfaces();
builder.RegisterType<CarCatalogContext>();
builder.RegisterGeneric(typeof(CarCatalogRepository<>)).As(typeof(IAsyncRepository<>)).InstancePerLifetimeScope()
.PropertiesAutowired()
.OnActivated(args => AutofacHelper.InjectProperties(args.Context, args.Instance, true));
builder.RegisterType<AutofacValidatorFactory>().As<IValidatorFactory>().SingleInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment