v6.0.0
Version 6.0.0 represents a major update in the Autofac internals. While every effort has been made to ensure code using version 5.x will continue to work exactly as you expect, you should be aware of the breaking changes and test things out. For the majority case, things should just continue to work; breaking changes are primarily in more rare advanced usage scenarios.
Check out the release blog post! Also, the documentation has been updated and is ready!
⚠️ Starting with Autofac 6.0, we now only targetnetstandard20andnetstandard21; we have removed the explicit target fornet461.The impact to you is that, while Autofac will still work on .NET Framework 4.6.1 as it did before, we strongly encourage you to upgrade to .NET Framework 4.7.2 or higher, as per the .NET Standard Documentation, to avoid any of the known dependency issues when using .NET Standard packages in .NET Framework 4.6.1.
New Features
There are a lot of new features, but the big ones are here. Other features and fixes will be outlined in the Issues section, below.
- Pipelines: This is the major change in Autofac v6 - all resolution activities internally now flow through pipelines, similar to how ASP.NET Core requests flow through pipelines. This allows for better customization in how things get resolved as well as enabling support for more new features.
- Composites: The composite pattern allows a collection of objects to be treated as though it's a single object.
- Diagnostics: Autofac v6 adds support for
DiagnosticSourcediagnostics. The core Autofac package ships with a default text-based diagnostic tracer and the newAutofac.Diagnostics.DotGraphpackage adds graphic tracing using DOT and Graphviz. - Generic Delegate Registrations: You can now register an open generic associated with a delegate/lambda expression, allowing you to provide a custom factory to resolve generics just like you do with non-generic types.
- Concurrency Performance Improvements: We focused a lot on performance and have removed a lot of locking. In some highly-concurrent cases, we've seen a 4x speed increase.
Issues and PRs
The following issues have been addressed in v6:
- #718: Circular dependency support using property injection and relationships like
Lazy<T>should now work. - #788: DOT graph support has been added via the
Autofac.Diagnostics.DotGraphpackage. - #798 / #1148: Circular dependency handling uses the .NET runtime to check stack depth when checking for circular dependencies rather than using a fixed stack depth.
- #828: The
ILifetimeScope.LifetimeScopeEndingevent is raised and completes before the scope is disposed. - #970: The composite pattern is now supported.
- #1069 / #1172: Core Autofac events are now async-friendly.
- #1120 / #1128:
ContainerBuilderis nowsealed. - #1123: Explicitly injected properties can now be declared using an expression.
- #1126 / #1169: Diagnostics are handled via
DiagnosticSource. - #1162: A new "pooled" lifetime type has been added via the
Autofac.Poolingpackage.
Breaking Changes
We'll do our best to keep an upgrade guide with breaking changes available and up to date. We're pretty sure we caught them all, but if you find a gotcha, let us know on the Documentation repo.
A summary of the breaking changes is as follows:
net461is no longer targeted; Autofac now targetsnetstandard2.0andnetstandard2.1.- Activation events are no longer exposed - this all happens through middleware now.
- If you were using an Autofac module to attach to activation events and inject parameters, similar to the way the
log4netmodule example is shown in the documentation, this now needs to happen through middleware. Thelog4netmodule example has been updated to show you the new way it works. RegistrationBuilder.RegistrationDatano longer exposes activation handlers. TheCoreEventMiddlewareis the source of events now.IComponentRegistrationno longer exposes activation events. TheCoreEventMiddlewareis the source of events now.
- If you were using an Autofac module to attach to activation events and inject parameters, similar to the way the
- Interface changes:
IConstructorSelectorimplementations need to switch to useBoundConstructorinstead ofConstructorParameterBinding.IRegistrationSourceimplementations need to update theRegistrationsFormethod signature.IInstanceActivatorimplementations no longer have anActivateInstancemethod and instead have aConfigurePipelinemethod.IComponentRegistryno longer supplies aDecoratorsFormethod to check decorators. UseIComponentRegistry.ServiceMiddlewareForinstead.- The
ResolveRequestconstructor now takes aServiceRegistrationinstead of anIComponentRegistration.
ContainerBuilderis nowsealed.- Autofac is no longer marked CLS compliant. The Microsoft
DiagnosticSourceand related entities we (and ASP.NET Core, and others) use for diagnostics is not CLS compliant so Autofac can't be, either.
Still Todo
We're working hard to get all of the ~25 integration packages pushed to NuGet as quickly as we can, so please bear with us while we get these sorted.
Some of this is sitting in branches ready to go, other things need to be done now that we have this core package out there.
If your favorite integration isn’t ready yet, we’re doing our best. Rather than filing "When will this be ready?" issues, consider pull requests with the required updates.