Skip to content

v6.4.0

Compare
Choose a tag to compare
@tillig tillig released this 25 May 20:55
· 177 commits to develop since this release
  • 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");
  });