Comments (3)
Okay from that example that is not possible due to the way that we have to hook into the functions.
One possible solution, albeit less than ideal I know, is to create an object that accepts all the dependencies and then inject that single object into each function.
Let me know if you have any further questions about this.
from azure-function-autofac-dependency-injection.
Can you clarify your question and potentially provide an example? Since this is just Autofac when you register all the dependencies with the container they can be injected into the constructors without a problem.
If you are asking if it is possible to create a construction on the function itself and inject there then the answer is no. That is an unusual use case however so I don't think that is what you are probably trying to do.
from azure-function-autofac-dependency-injection.
Sure, this is an example of what I'm trying to do:
[DependencyInjectionConfig(typeof(DIConfig))]
public class Function1
{
private readonly ISampleService _sampleService;
public Function1([Inject] ISampleService sampleService)
{
_sampleService = sampleService;
}
[FunctionName("Function1")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
_sampleService.Add();
....
}
I have quite a few dependencies (this ofcourse is simplified) but I would like to inject them in the class constructor so that I don't have to have all of them as function parameters.
from azure-function-autofac-dependency-injection.
Related Issues (20)
- Configuration Settings not picked up from appsettings.json file HOT 3
- Configuration Dependency Injection HOT 4
- IOptions DI in Azure Function HOT 3
- "A second operation started on this context before a previous asynchronous operation completed" HOT 20
- Autofac with Azure Functions with IWebJobsBuilder for constructor DI HOT 3
- IHttpClientFactory injection problem HOT 6
- Allow newer versions of Autofac to be used HOT 3
- Inject function parameters HOT 7
- Upgrade to Core 3.1 HOT 2
- RegisterAssemlyTypes now working for ClosedTypes HOT 3
- RegisterLoggerFactory doesnt work HOT 1
- Dependency resolution graph for injected services HOT 2
- Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.xxxx'. mscorlib: Constructor on type 'xxx.xxx.Startup.AutofacConfig' not found HOT 13
- Container instances do not cache HOT 20
- ILifetimeScope not disposed on V1 functions HOT 5
- Pass a ContainerBuilder in HOT 9
- Registering PerFunctionScope
- Constructor not found for DI class with ctor signature DIConfig(string functionName, string baseDirectory, ILoggerFactory factory) HOT 3
- Support for HttpRequestMessage parameter in DI class HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-function-autofac-dependency-injection.