Autofac.Extensions.DependencyInjection | Autofac implementation of the interfaces | Dependency Injection library
kandi X-RAY | Autofac.Extensions.DependencyInjection Summary
kandi X-RAY | Autofac.Extensions.DependencyInjection Summary
Autofac is an IoC container for Microsoft .NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular .NET classes as components. Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Autofac.Extensions.DependencyInjection
Autofac.Extensions.DependencyInjection Key Features
Autofac.Extensions.DependencyInjection Examples and Code Snippets
Community Discussions
Trending Discussions on Autofac.Extensions.DependencyInjection
QUESTION
i have communication problem while retrieving data from the database
ContractDataService
...ANSWER
Answered 2022-Apr-03 at 23:40Add
QUESTION
I have created two static class DefaultRoles.cs
...ANSWER
Answered 2022-Mar-04 at 16:57Just add this code to program.cs file
QUESTION
We have a series of .NET Core console apps that are installed in a particular directory:
...ANSWER
Answered 2022-Jan-25 at 00:31Are the apps published as Single File Applications? If so, the documentation have some pointers.
Looking at the fact that it's extracting 3rd-party libraries, I'm guessing this may be relevant:
Previously in .NET Core 3.0, when a user runs your single-file app, .NET Core host first extracts all files to a directory before running the application. .NET 5 improves this experience by directly running the code without the need to extract the files from the app.
And this explains the location:
If extraction is used the files are extracted to disk before the app starts:
- If environment variable DOTNET_BUNDLE_EXTRACT_BASE_DIR is set to a path, the files will be extracted to a directory under that path.
- Otherwise if running on Linux or MacOS, the files will be extracted to a directory under $HOME/.net.
- If running on Windows, the files will be extracted to a directory under %TEMP%/.net.
QUESTION
sorry for this basic question, just want to ask why almost all third package comes with more than one packages on nuget? For example, Autofac comes as:
...ANSWER
Answered 2021-Dec-13 at 13:48One package is Autofac, the inversion of control container.
One package is the adapter that can convert Microsoft format registrations into Autofac registrations.
You can use Autofac without the adapter. Lots of people do, and this is how things work for non-.NET-core projects. Hence, it's two packages - you opt-in for the features you want.
It's the same reason you don't find all the classic ASP.NET, WCF, Moq, and other integration support in the core Autofac package.
QUESTION
I have a v3 Azure Function that runs fine locally, but after it's deployed I see the following exception related to a missing Entity Framework file:
2021-10-18T23:37:07.588 [Error] Executed 'MyFunction' (Failed, Duration=1807ms)
Autofac.Core.DependencyResolutionException : An exception was thrown while activating
Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor()' on type 'Repository'.
System.IO.FileNotFoundException : Could not find file 'D:\home\site\wwwroot\bin\DAOEntities.edmx'.at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode,FileShare share,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options)
at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,Boolean useAsync)
at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName)
at System.Xml.XmlWriter.Create(String outputFileName,XmlWriterSettings settings)
at System.Data.Entity.Infrastructure.DefaultDbModelStore.Save(Type contextType,DbModel model)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.AsNoTracking() at System.Data.Entity.Infrastructure.DbQuery
1.AsNoTracking()
at lambda_method(Closure ,Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
End of inner exception
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context,IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable
1 parameters)
End of inner exception
at Autofac.Core.Resolving.InstanceLookup.CreateInstance(IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope,ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context,Service service,IEnumerable
1 parameters,Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context,Service service,IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable
1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](ILifetimeScope scope)
at Autofac.Extensions.DependencyInjection.AzureFunctions.ScopedJobActivator.CreateInstance[T](IFunctionInstanceEx functionInstance)
at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory1.<>c__DisplayClass1_1.<.ctor>b__0(IFunctionInstanceEx i) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 20 at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory
1.Create(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 26
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 44
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 776
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 101
I've noticed locally that the .edmx
file isn't generated when the project is built -- instead it's created when I start running the project using func start
.
Could this be a permissions issue (e.g. with the function not having write access to the storage blob)?
...ANSWER
Answered 2021-Oct-21 at 00:46I've found that the root issue is related to the Run From Package
setting.
This prevents the function app from generating the .edmx
file, so the solution is to either disable Run From Package
or to deploy the function with the .edmx
file pre-included.
From MSDN: Run From Package makes wwwroot read-only, so you will receive an error when writing files to this directory. (https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package)
QUESTION
I have a problem with IAfterSaleService interface and AfterSaleService Class and I used autofac IoC for these cs files. However while constructor injection ı made is working for some interface, aftersaleservice is not working for some constructor injection. For example, While IAfterService works in the constructor of AfterServiceController, it does not work in the constructor of other service(like OrderService.cs...) in the same directory
I am getting following exception response
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Retail.Business.Concretes.AfterSaleService -> Retail.Business.Concretes.OrderService. ---> Autofac.Core.DependencyResolutionException: Circular component dependency detected: Retail.Business.Concretes.AfterSaleService -> Retail.Business.Concretes.OrderService -> Retail.Business.Concretes.AfterSaleService.
With the following stack trace:
...ANSWER
Answered 2021-Oct-16 at 09:31The error is pretty clear:
Circular component dependency detected
Your AfterSaleService
depends on IOrderService
and OrderService
depends on IAfterSaleService
which for obvious reasons will make it impossible for DI container to resolve the dependencies during construction. Personally I try not to inject dependencies of the same "level", i.e. repositories does not accept repositories, services - services and controllers do not depend on the other controllers so my recommendation would be to refactor your application so you don't need such injections (maybe introduce one more layer or move common code to static helpers or something else).
If it is not feasible ATM to rewrite due to amount of work you can use work around the issue for now - inject same level dependencies as Func
's. Autofac
provides Func
resolutions out of the box (i.e. if you register IService
you can resolve Func
without any extra registrations), so you can do something like this:
QUESTION
I am trying to create some tenants for my test. I am using the template created at the ABP Framework website (.NET Core, Angular, version 4.4). In my TestBaseModule, I have added this:
...ANSWER
Answered 2021-Sep-17 at 13:32Don't change your SeedTestData
method. Because it's responsible for seed your test data. You don't need to add TenantTestDataBuilder
to seed your tenant-related data. It's also responsible for that too.
QUESTION
I have an ASP.NET Core 5 MVC application and I use Autofac as my IoC container. To integrate Autofac with ASP.NET Core I use Autofac.Extensions.DependencyInjection package. I'm looking for a way to register services from dynamically loaded assembly. I know that I can do that on application startup, but I need to do that at some later point in time. E.g. user goes to admin page and enables some module. During HTTP request processing I'd like to load assembly corresponding to that module and register services from that assembly. Do you have any idea how to do that?
...ANSWER
Answered 2021-Jan-22 at 15:09The short answer here is, no, you can't update the container. As of Autofac 5.x, the container is immutable. Which is to say, you can't modify the contents once it's built.
The documentation explains why this is actually a good thing. One example: Let's say you have a singleton that keeps a list of all the currently enabled plugins. If you enable a new plugin, that singleton needs to be totally disposed and rebuilt. But now what if you have some sort of other manager class that uses the singleton? It also needs to be rebuilt so it has the new singleton that has the updated list of plugins.
Changing the container has a huge trickle-down effect like this on a lot of things.
Instead of trying to use Autofac as the feature flag or enabled/disabled mechanism, I'd recommend updating your design such that all the plugins available are loaded but possibly they don't actually get used unless they're enabled.
There are lots of ways to do that. I won't list literally all of them, but here are a couple of ideas to get you started. Also, these are skeleton ideas, you'll have to fill in some of the code gaps. It won't be copy/paste... I unfortunately don't have that kind of time. :(
Idea 1: Singleton Plugins, Name and Enabled PropertiesYou could define a plugin interface to be something like:
QUESTION
I am getting following error:
Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(System.String, Int32)' on type 'AerospikeClient'.
Following is the stacktrace of autofac:
at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.b__11_0(ResolveRequestContext ctxt, Action
1 next) at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action
1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) --- End of inner exception stack trace --- at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action
1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action
1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action
1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext ctxt) at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable
1 parameters) at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters) at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
Following is my registration:
...ANSWER
Answered 2021-Jan-18 at 09:54Check the actual type returned from _configuration["AerospikeHostName"]
. Is it actually string
, or is it something that happens to be assignable to string?
Equally, check the actual value used is valid, because Autofac should be fine expecting that string value.
Also, in future, consider using the built-in diagnostics to get a clearer picture of what exceptions are being thrown during resolve operations.
QUESTION
I have a solution with target framework of 4.7.1. I have locally installed dotnet core sdks and able to issue build, publish commands.
My project file looks like this, with many references to dotnet core dlls
...ANSWER
Answered 2020-Dec-21 at 11:31.NET Core is different as compared to .NET Framework.
Moreover, if you want to create a pipeline for your .NET Framework project, you cannot use .NET Core tasks. Your YAML
file of Pipeline
should look like below:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Autofac.Extensions.DependencyInjection
Reference the Autofac.Extensions.DependencyInjection package from NuGet.
In your Program.Main method, where you configure the HostBuilder, call UseAutofac to hook Autofac into the startup pipeline.
In the ConfigureServices method of your Startup class register things into the IServiceCollection using extension methods provided by other libraries.
In the ConfigureContainer method of your Startup class register things directly into an Autofac ContainerBuilder.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page