
A new version of Azure Functions was just released, called 1.0.19. While there are quite some changes in this release, like the fact that Function Apps must have exactly one single language and WebJobs had been updated to 3.0.0-beta8, there are some breaking changes. For complete information about the changes see the announcement.
Breaking Changes
Azure Functions Version 1.0.19 comes with some breaking changes. Extensions cannot be created like they had been before. Have a look at these links:
- Breaking change in ExtensionConfigContext
- Subtle differences in DI between WebJobs.Script.WebHost and Microsoft.Azure.WebJobs/Microsoft.Extensions.DependencyInjection
As AutofacOnFunction relies on the ExtensionConfigContext, there was some stuff to do. Actually, it was possible to fix all breaking changes in the AutofacOnFunctions nuget package itself. While these fixes had been applied, I just introduced a small feature that had been requested by community.
Named Services
Autofac allows for named services. AutofacOnFunctions had been enhanced to support named services in most initutive way. Actually there are only two steps to do.
First register your services by name.
Use the inject atttribute to specify the named instance:
There are two samples available that work identically:
Net Standard
Net Framework
benjamin
November 20, 2018 at 12:48 pmThis is really great !
can you use parameters in the name ?
function :
[HttpTrigger(AuthorizationLevel.Anonymous, „get“, „post“, Route = „demo/{myParam}“)]HttpRequest req,
string myParam,
[Inject(„named{myParam}“)] IEventValidator validator,
module :
builder.RegisterType().Named(„namedA“);
builder.RegisterType().Named(„namedB“);
thanks
Holger Leichsenring
November 21, 2018 at 10:04 amHi Benjamin,
no, this is not supported by now, but it is a quite interesting idea. 🙂
As the HttpTrigger supports that, just one question to the „[Inject(“named{myParam}”)]“. You registered the type via names namedA and B. Does it mean, myParam is either A or B? There is one problem in resolving the type. I need to check if it is possible to read out all parameters to use myParam for resolving named{myParam}. Will have a look!
Holger
benjamin
November 21, 2018 at 11:02 amhi Holger
yes, myParam is either „A“ or „B“
there is a problem in my previous comment , we should read :
module :
builder.RegisterType ().Named(“namedA”);
builder.RegisterType ().Named(“namedB”);
this should really be a great feature !
thanks
benjamin
November 21, 2018 at 11:03 amgenerics in html :/
builder.RegisterType EventValidatorA ().Named(“namedA”);
builder.RegisterType EventValidator ().Named(“namedB”);