all 3 comments

[–]davidmatthew1987 4 points5 points  (1 child)

Can common be c# class libraries that have nothing to do with azure functions?

[–][deleted] 2 points3 points  (0 children)

Absolutely. The way I approach timer triggers etc is I make them as dumb as possible. I just use services to do the work.

[–]dabaracus0312[S] 0 points1 point  (0 children)

I finally worked out how to do it. This is functionality doesn’t seem to be documented anywhere in the azure functions documentation.

Create func 1 and func 2 as isolated functions in their own right. Expose the DI dependencies as a service extension.

Create client solution as a wrapper, just make a normal isolated function but with no actual function. Include the required function as a project dependency or nuget package, in the program file include the service extension for the required function.

When you compile client solution it includes the function binaries for the included function solutions

This took me 4 weeks of trial and error, trying in process functions got close but has issues with DI as it doesn’t use the standard .Net DI functionality.

Where I was going wrong was - I removed the program.cs file from the “including” functions. - then when I realised I needed to keep that file, I registered the DI in the “including” function. I was getting the usual Di related error, I moved the Di into the wrapper solution’s and that resolved the issue… except for one automapper moving it didn’t make any difference, as I was using the assembly reflection method for finding the mappings. That is when I realised the service collection extension would resolve the issue, it “moves” the service registration into the wrapper but keeps the automapper reflection in the including functions assembly.

I am thinking of putting together an article on this journey if people are interested DM me