Skip to content

Releases

v9.3.4

Choose a tag to compare

@tillig tillig released this 18 Sep 16:09
ae9e1e1

What's Changed

Do not build a held registration's pipeline early by @tillig in #1504 (fixes #1503) - a regression introduced in 9.3.3. Registering an open generic for several services (.As(typeof(IFirstService<>)).As(typeof(ISecondService<>))) threw InvalidOperationException: Component pipeline has already been built, and cannot be modified. on first resolve whenever anything attached to PipelineBuilding from the component registry's Registered event. Autofac.Extensions.DependencyInjection attaches exactly that way on every registration, so ASP.NET Core applications using a multi-service open generic registration hit it deterministically. The fix restores the ordering 9.3.2 had, where the pipeline is built only after Registered has been raised.

If you are on 9.3.3 and register an open generic against more than one service, upgrade. Thanks to @hjalle for the report and for pinning it to the exact line.

Full Changelog: v9.3.3...v9.3.4

v9.3.3

Choose a tag to compare

@tillig tillig released this 17 Sep 21:33

What's Changed

  • Create AnyKey adapter registrations per registry by @tillig in #1498 (fixes #1497) - the KeyedService.AnyKey fallback adapter was cached and handed to every registry that asked for it, so the first scope to receive it built and disposed its pipeline out from under the rest. Other scopes then failed to add middleware, resolved through a disposed activator, or adapted another scope's registration. Multitenant containers hit this most often.
  • Fix open generic multi-service registrations overriding later defaults by @tillig in #1499 (fixes #1465) - a registration source exposing one component for several open generic services applied it to all of them at once, landing it ahead of higher-priority sources those services had yet to query. Whichever service was resolved second got the shared component instead of its own overriding registration. Source priority rather than resolution order now decides the default; closed generic types were never affected.
  • System.Diagnostics.DiagnosticSource and Microsoft.Bcl.AsyncInterfaces (netstandard2.0 only) move to 10.0.12.

Full Changelog: v9.3.2...v9.3.3

v9.3.2

Choose a tag to compare

@tillig tillig released this 02 Aug 00:02

What's Changed

  • Reduce registration cost incurred by scans for [ServiceKey] attribute by @npease18 (#1495, fixes #1480)

New Contributors

Full Changelog: v9.3.1...v9.3.2

v9.3.1

Choose a tag to compare

@tillig tillig released this 09 Jul 17:12

What's Changed

Fix per-resolve closure allocation in resolve pipeline (#1493) by @tillig in #1494

Full Changelog: v9.3.0...v9.3.1

v9.3.0

Choose a tag to compare

@tillig tillig released this 20 Jun 06:20
b7f65d6

What's Changed

  • Annotate core for trimming and Native AOT compatibility by @tillig in #1492

Full Changelog: v9.2.0...v9.3.0

v9.2.0

Choose a tag to compare

@tillig tillig released this 16 Jun 21:25

What's Changed

  • Fix decorator parameter selection for derived-service dependencies (#1459) by @tillig in #1484
  • Dispose container when an IStartable throws during Build (#1392) by @tillig in #1485
  • Honor ExternallyOwned ownership for decorators (#1402) by @tillig in #1486
  • Only subscribe Module registry events when hooks are overridden (#1446) by @tillig in #1487
  • Prefer a complete generic argument mapping for multi-interface open generics (#1464) by @tillig in #1489
  • Fail fast when a scope-local registration binds its lifetime to an ancestor scope (#1460) by @tillig in #1488
  • Add GetRegistrationId extension to expose a registration's unique ID (#1327) by @tillig in #1490
  • Cache compiled factory-delegate generators to avoid recompilation across scopes (#1461) by @tillig in #1491

Full Changelog: v9.1.0...v9.2.0

v9.1.0

Choose a tag to compare

@tillig tillig released this 12 Mar 21:43
a6a8c62

This is a pretty big release for Autofac with some major new functionality!

AnyKey Support

First, Autofac now natively supports the concept of AnyKey. It behaves the same way AnyKey works in Microsoft.Extensions.DependencyInjection, but it is native to Autofac directly. The unit tests here show some very detailed examples of usage, but on a high level:

var builder = new ContainerBuilder();
builder.RegisterType<Service>().Keyed<IService>(KeyedService.AnyKey);

var container = builder.Build();

// Registering as AnyKey allows it to respond to... any key!
var service = container.ResolveKeyed<IService>("service1");

Inject Service Key Into Constructors

The new [ServiceKey] attribute allows you to inject the service key provided during resolution. This is handy in conjunction with AnyKey. Again, this is similar to the construct in Microsoft.Extensions.DependencyInjection, but with native Autofac.

First, mark up your class to take the constructor parameter.

public class Service : IService
{
  private readonly string _id;
  public Service([ServiceKey] string id) => _id = id;
}

Then when you resolve the class, the service key will automatically be injected.

You can also make use of this in a lambda registration.

var builder = new ContainerBuilder();
builder.Register<Service>((ctx, p) => {
  var key = p.TryGetKeyedServiceKey(out string value) ? value : null;
  return new Service(key);
}).Keyed<Service>(KeyedService.AnyKey);

Metrics

Some metrics have been introduced that can allow you to capture counters on how long middleware is taking, how often lock contention occurs, and so on.

Set the AUTOFAC_METRICS environment variable in your process to true or 1 to enable this feature. You can see the set of counters that will become available here.

⚠️ This is NOT FREE. Collecting counters and metrics will incur a performance hit, so it's not something you want to leave on in production.

General Performance Improvements

A pass over the whole system was made with an eye to trying to claw back some performance. Some additional caching was introduced to help reduce lookups and calculations of reflection data; and a few hot-path optimizations were made for the common situations.

Full Changelog: v9.0.0...v9.1.0

v9.0.0

Choose a tag to compare

@tillig tillig released this 18 Nov 18:12
17ccc0b

Updated Autofac for .NET 10. New current set of target frameworks: net10.0;net8.0;netstandard2.1;netstandard2.0

Breaking Changes

Dropped support for net6.0, net7.0.

Additional Changes

  • Added support for net10.0.
  • Updated dependencies:
    • System.Diagnostics.DiagnosticSource 8.0.1 => 10.0.0
    • Microsoft.Bcl.AsyncInterfaces 8.0.0 => 10.0.0

Full Changelog: v8.4.0...v9.0.0

v8.4.0

Choose a tag to compare

@tillig tillig released this 04 Aug 16:54

Minor breaking change: The shim RequiresUnreferencedCodeAttribute has been changed from public to internal (#1462/#1463 - thanks @prochnowc!). This will only affect people targeting older/lower .NET standard frameworks who also rely on the shim attribute in Autofac. While it's technically breaking, it didn't seem like a great reason to do a full major release due to the edge case nature of the set of applications/users affected.

v8.3.0

Choose a tag to compare

@tillig tillig released this 07 May 18:29

What's Changed

  • Corrected nullable markup on IIndex<K,V>.TryGetValue() since it may return null on failure.
  • Composite services can now be keyed (#1458 - thanks @syko9000!)
  • Packages for core Autofac are no longer published to MyGet. Instead, builds are now available from GitHub Packages This also means the actual packages themselves won't be manually attached to the release - you can get them from the package source now.

Full Changelog: v8.2.1...v8.3.0