0

From the Autofac documentation:

Autofac overrides component registrations by default. This means that an application can register all of its default components, then read an associated configuration file to override any that have been customized for the deployment environment.

How can i override registration, firstly i make assebly scan,

builder
   .RegisterAssemblyTypes(assembly)              
   .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies)
   .AsImplementedInterfaces()
   .AsSelf()
   .InstancePerRequest();

Then try to update registration without scope tag

builder
    .RegisterType<NotPerRequestType>()
    .AsImplementedInterfaces();

But there are still 2 registrations and i still getting no matching tag error wher i resolve NotPerRequestType.

Steven
  • 166,672
  • 24
  • 332
  • 435
Horosho
  • 647
  • 1
  • 8
  • 22

1 Answers1

2

You can't change a registration post-facto. You'd need to exclude the stuff you don't want registered during assembly scanning by using LINQ.

builder.RegisterAssemblyTypes(assembly)
       .Where(t => t != typeof(NotPerRequestType))
       ...

Then you'll only have the one registration - the one you manually register later.

This is, unfortunately, the "two-edged sword" of trying to automatically just register everything and then realizing you have exceptions. You really need to use blanket assembly scanning with great care.

Travis Illig
  • 23,195
  • 2
  • 62
  • 85
  • 4
    Also, instead of the ".Where(t => t != typeof(NotPerRequestType))" he can use the "Except" method AutoFac provides. Example: ".Except()" – m1o2 Aug 19 '17 at 21:15