c# - Autofac how to update registration? -
from autofac documentation:
autofac overrides component registrations default. means application can register of default components, read associated configuration file override have been customized deployment environment.
how can override registration, firstly make assebly scan,
builder .registerassemblytypes(assembly) .propertiesautowired(propertywiringoptions.allowcirculardependencies) .asimplementedinterfaces() .asself() .instanceperrequest();
then try update registration without scope tag
builder .registertype<notperrequesttype>() .asimplementedinterfaces();
but there still 2 registrations , still getting no matching tag error wher resolve notperrequesttype.
you can't change registration post-facto. you'd need exclude stuff don't want registered during assembly scanning using linq.
builder.registerassemblytypes(assembly) .where(t => t != typeof(notperrequesttype)) ...
then you'll have 1 registration - 1 manually register later.
this is, unfortunately, "two-edged sword" of trying automatically just register everything , realizing have exceptions. need use blanket assembly scanning great care.
Comments
Post a Comment