Skip to content

Instantly share code, notes, and snippets.

@Manu06D
Last active August 2, 2020 18:57
Show Gist options
  • Save Manu06D/c32760dcc9f944b8d7caedfafdc1bfb9 to your computer and use it in GitHub Desktop.
Save Manu06D/c32760dcc9f944b8d7caedfafdc1bfb9 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,
Assembly.GetExecutingAssembly()
});
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