Releases: autofac/Autofac
v8.2.0
What's Changed
- Fix #1437: Improve type cache handling for generic type arguments with respect to
AssemblyLoadContext
disposal (#1438 - thanks @hemirunner426!) - Added overloads for
RegisterServiceMiddleware
to assist with interceptors/decorators (#1439 - thanks @idiotsky!)
Full Changelog: v8.1.1...v8.2.0
v8.1.1
What's Changed
- Fix boxing in
ResolveRequest.operator==()
(#1430, thanks @SergeiPavlov!) - Remove redundant null-checking in resolution extensions (#1428, thanks @SergeiPavlov!)
- Fix #1427: Ensure
WithProperty
registration methods consistently allow null values (#1428)
Full Changelog: v8.1.0...v8.1.1
v8.1.0
What's Changed
- Optimized
required
member caching (#1415 - thanks @SergeiPavlov!) - Correctly handle polyfilled
required
infrastructure attributes by (#1421 - thanks @DoctorVanGogh!) - Improve memory management in registered services tracking (#1423 - thanks @snaumenko-st!)
- Fix #1330: Generic decorators attached to generics that expose multiple service types should be handled properly (#1424)
Full Changelog: v8.0.0...v8.1.0
v8.0.0
Breaking Changes
- Removed
netcoreapp3.1
support/testing (#1401). - Converted
ResolveRequest
into areadonly struct
(#1397 - thanks @SergeiPavlov!).
Additional Changes
- Added
net8.0
target (#1401). - Replaced use of Moq in tests with NSubstitute (#1390 - thanks @aydjay!).
Full Changelog: v7.1.0...v8.0.0
v7.1.0
What's Changed
- Fix #1388: Re-enabled
RegsiterTypes
filtering. This was an accidental behavior regression where theRegisterTypes
method wouldn't filter out non-registerable types. RegisterType<T>
andRegisterType(Type t)
will now throw when non-registerable types are provided, for examplecontainerBuilder.RegisterType<IInterface>()
(you can't register interfaces - you can register thingsAs<IInterface>
). This used to throw at container build time; now it throws atRegisterType
time and it has a more precise error message so you can handle these issues more proactively.
Full Changelog: v7.0.1...v7.1.0
v7.0.1
What's Changed
- Reduced lock contention in
LifetimeScope.CreateSharedInstance
(thanks @botinko) - Optimized
Autofac.Features.OpenGenerics.OpenGenericServiceBinder.TryBindOpenGenericTypedService
(thanks @SergeiPavlov)
Full Changelog: v7.0.0...v7.0.1
v7.0.0
Version 7.0.0 is a major increment due to some changes in the target frameworks and some behavioral changes. We summarize these in the documentation, but included here as well:
New Features
- Properties marked
required
will now be injected by default. As part of this, the default property injector usingPropertiesAutowired()
will not inject properties markedrequired
. The documentation has more explanation with examples. - Ability to isolate
AssemblyLoadContext
by lifetime scope. A new method,BeginLoadContextLifetimeScope
, has been added that allows you to create a lifetime scope tied to a specificAssemblyLoadContext
. When the scope is disposed, Autofac will perform a best-effort release of all references to types from that context so the assemblies can be unloaded. The documentation explains this in greater detail. - Documentation links in exception messages. Common Autofac exceptions now include links to our online documentation to help you understand what the exceptions mean and how to troubleshoot them.
Issues and PRs
- Add documentation links to common exceptions by @tillig in #1359
- Fix #1360: Unify the "no constructors found" reporting by @tillig in #1362
- Add support for required properties by @alistairjevans in #1364
- Mark RegisterGeneratedFactory obsolete by @tillig in #1366
- Isolate service information computed in child scopes from the parent scope by @alistairjevans in #1350
Full Changelog: v6.5.0...v7.0.0
Breaking Changes
net50
no longer targeted. Autofac will still work with .NET 5 via thenetstandard2.1
target, but we recommend you upgrade to a later, supported version of .NET.- Properties marked
required
will now be injected by default. As noted above,required
properties will be injected. This is a behavioral change from Autofac 6.0. - Default property injection ignores
required
properties. UsingPropertiesAutowired()
will ignorerequired
properties because it's assumed they must be set during construction rather than post-object-creation. RegisterGeneratedFactory
is obsolete. This feature has been replaced by theFunc<X, Y, B>
built-in relationship and delegate factories.ILifetimeScope
has a newBeginLoadContextLifetimeScope
method. If you have mocks ofILifetimeScope
this method must now be implemented.
v6.5.0
- Reflection caches have moved to a central location
Autofac.Core.ReflectionCacheSet
(#1341). This is part of an effort to support unloadingAssemblyLoadContexts
associated with child scopes and enable better plugin support (#1324). IDecoratorContext
now extendsIComponentContext
so decorator decisions can be made based on the constructed container (#1338, #1352).- Fix memory leak regression (#1353 - Thanks @botinko!)
Full Changelog: v6.4.0...v6.5.0
v6.4.0
- Fix typos in exception messages (#1301, #1302, #1323)
- Enable open generic assembly scanning to use
WithMetadata
and generate metadata (#1299 - thanks @romerod!) - Package targets .NET 6 TFM (#1306)
- README included in NuGet package (#1295, #1308)
- Symbols published in .snupkg format (#995, #1309)
- Fix issue where changing type parameter names caused generic resolution to fail (#1315, #1316)
- Added generic delegates to make registering lambda components easier (#1320, #1321)
- Optimization of reflection activation for components that only have one constructor - specifically, if there is only one constructor on a component, that constructor is cached as the one for activation and
IConstructorSelector
invocation is skipped (#1325)
The new feature to be aware of here is the generic delegates for making lambda registrations easier (#1320, #1321). It makes resolving dependencies in lambdas more straightforward.
The old way meant injecting an IComponentContext
and resolving the dependencies manually.
builder.Register(
ctx =>
{
var dep1 = ctx.Resolve<IDependency1>();
var dep2 = ctx.Resolve<IDependency2>();
return new Component(dep1, dep2, "configuration-value");
});
That old way still works and is not deprecated. You can keep doing that.
However, you can now skip the manual resolutions and just provide the dependencies as the parameters to the lambda:
builder.Register(
(IDependency dep1, IDependency dep2) =>
new Component(dep1, dep2, "configuration-value"));
If you need both the context and dependencies for advanced cases, you can do that, too.
builder.Register(
(IComponentContext ctx, IDependency dep1) =>
{
var dep2 = ctx.Resolve<IDependency2>(new NamedParameter("p", "someValue"));
new Component(dep1, dep2, "configuration-value");
});
v6.3.0
- Modules can now be registered conditionally using an
OnlyIf
clause. (#1235, #1272) - Delegate factories will no longer allow parameters with the name
value
to inject by name as that's a reserved word in property setter methods. (#1275) IAsyncDisposable
instances that have not been activated are correctly disposed when the scope is disposed. (#1285)- There are now generic overloads for
TryResolveNamed
andTryResolveKeyed
. (#1263, #1287 - thanks @v0idzz!) - Fixed performance regression in assembly scanning with respect to compiler generated types. (#1289 - thanks @RogerKratz!)