4,341 questions
0
votes
0
answers
7
views
Why Castle.DynamicProxy could not create proxy class when origin class has a decimal paramter method
Old .net framework 4.8 project, use AutoFac.
I want to use AOP to instrument every method , but some class throw exception : System.Decimal is not a supported constant type.
There are a lot of methods ...
0
votes
1
answer
26
views
Autofac Resolve is extremely slow in .NET Generic Host HostApplicationBuilder
We have been using Autofac since .net framework 4.8 and its performance has been looking fine. However when we are trying to use exactly the same code into Console Application which is based on .net ...
3
votes
1
answer
68
views
How to Use UnsafeAccessor to Check if Autofac.Core.Lifetime.LifetimeScope IsDisposed in .NET 8?
I'm currently working on a project using .NET 8 and Autofac for dependency injection. I've encountered a scenario where I need to check if an instance of Autofac.Core.Lifetime.LifetimeScope is already ...
1
vote
1
answer
37
views
Injected instance not received/not the same when manually resolving an InstancePerLifetimeScope type
I have the following registration code:
private static IContainer BuildContainer()
{
var builder = new ContainerBuilder();
// current assembly
builder.RegisterApiControllers(Assembly....
0
votes
1
answer
25
views
Registering the container itself with Autofac does not work in ASP.NET Web API on .NET 4.7.2
The following does not work for me:
IContainer container;
ContainerBuilder builder = new ContainerBuilder();
container = builder.Build();
builder.RegisterInstance(container).As<IContainer>();
...
0
votes
1
answer
26
views
Stopping Autofac-Registered Background Services via External Requests
I have multiple background services that are generally categorized by their operation types (e.g., daily, monthly). To avoid defining features like exception logging and task execution control (the ...
0
votes
0
answers
27
views
Implement DownstreamApi in a project .net framework 4.8 with OWIN and AutoFac
I need to implement the method
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection(""))
.AddInMemoryTokenCaches();
in a project with a .net framework 4.8 with OWIN ...
0
votes
0
answers
14
views
Execution timing of Autofac OnActivated (Z.EntityFramework.Plus)
I use Autofac to replace ASP.NET default DI container.
I create a db filters with Z.EntityFramework.Plus;.
I need to apply these filters, when DbContext was Activated.
At first I use .NET 6 ...
0
votes
0
answers
29
views
When using autofac multitenant, how can we inject a tenant-scoped service in an AuthenticationHandler
We are trying to implement multitenancy in a .Net Core 8 application, using the Autofac.AspNetCore.Multitenant package.
We identify tenants based on HTTP headers set by a reverse proxy.
We have ...
1
vote
1
answer
142
views
Autofac generic decorator for different interfaces with the same basis
I have an application that is made up of two layers, WebApi and Domain.
The WebApi has controllers that invoke the business logic in the domain through an interface that is called IInteractor.
public ...
1
vote
3
answers
98
views
Polymorphic DI framework or setup for .NET?
The situation that I have is the following and albeit quite simple, it seems not to be supported (at least out of the box) for 2 DI frameworks that I tried.
public interface IPlugin
{
// misc
}
...
0
votes
0
answers
33
views
How to Instantiate a Class with dependency on IIndex in Autofac with C# .NET Framework
I am using autofac with Keyed type registration in C# .NET 4.7 to choose concrete classes at runtime. The following approach works, but I'm not convinced it's the best.
I have a class like this:
...
0
votes
0
answers
81
views
Confused how to handle dispose. Especially with DI container and constructor injection
Bit confused about IDispose.
How does IDispose tell the GC that it can remove this instance from memory?
Not totally sure what: GC.SuppressFinalize does.
In this example repositories should also be ...
0
votes
1
answer
258
views
Is there a way to use Autofac Service Registration With Microsoft DI
I have some legacy projects that use Autofac for their DI container and they have all of their registration nicely organized into Modules. I have a new .net 8 API project and some flows need to ...
0
votes
1
answer
67
views
Example of multitenant with generic host in C#
I have not found a solution (or example of) using multitenancy with a generic host in C#.
The examples given in the Autofac repository (ConsoleApp, MVC and WCF) uses a strategy that is not supported (...
0
votes
0
answers
50
views
MediatR+Autofac NotificationHandler decorator pattern strange behaviour
I'm having a very strange issue with decorator pattern using MediatR (12.4.0) and Autofac (8.0.0) but I really cannot understand wether the problem is concerning Autofac, MediatR or (more probably) my ...
0
votes
0
answers
37
views
Depedency Injection with Autofac and Automapper
I have project where I implement Autofac and Automapper. There is no any problem when I added Automapper, but when I want to add mine implementation of interface I came across error with Automapper. ...
1
vote
1
answer
33
views
Autofac reporting circular dependency only when using keyed attribute
I'm trying to inject a specific keyed object into another's constructor, but autofac 8.0.0 raises an exception that there is a circular dependency: Circular component dependency detected: ...
0
votes
0
answers
38
views
The Web API responds to the browser before the await Task.Delay finished executing
I'm working on an OWIN ASP.NET Web API 2 application which uses Autofac.
I ran into some issues because some code after await is never executed when the client app (browser) is cancelling the request.
...
-1
votes
1
answer
34
views
Autofac DI and "Child" Scopes
I have a project where I use Autofac to create UI components.
I would like some of my Autofac-created UI components to have child components that can potentially reference their parent.
What is the ...
1
vote
0
answers
36
views
How to make Worker class compatible with AutoFac also with Microsoft Dependency Injections
I have an worker service what will be consumed in two project.
First project use Autofac for dependency injection the other use Microsoft.Extensions.DependencyInjection
First Worker look like:
public ...
0
votes
2
answers
78
views
Second Mediator Call Fails with ObjectDisposedException in ASP.NET Core Using Autofac: "Instances cannot be resolved as it has already been disposed"
I am trying to run two mediator calls inside a method. For some reason, the second mediator call always fail. I am expecting both calls to run without error. The full error message is:
System....
0
votes
0
answers
46
views
Autofac: None of the constructors found on type 'DataContext' can be invoked with the available services and parameters:
Title:
First time using AutoFac - Cannot resolve IDataContext in HomeController
Question:
I'm new to AutoFac and I'm facing an issue resolving dependencies for my HomeController which depends on ...
0
votes
0
answers
14
views
Is it possible to use Metdata Attribute for generic interface implemenations?
For below IMyInterface implementation is it possible to get meta data ienumerable as
IEnumerable<Meta<IMyInterface<IGenericType>>> MetdataList { get; set; }
public interface ...
0
votes
0
answers
23
views
Autofac Generics Registration
I have one c# project which is using libraries from Ardalis Specification , I need to work with two different DbContext.
So, from Autofac side I need to register generics which will implement ...
0
votes
1
answer
19
views
how to inject component to constructor parameter using configuration file
I'm trying to inject constructor parameters using a configuration file, but it seems autofac only supports builtin primitive types, any suggestions? thanks
following is the code
{
"...
0
votes
0
answers
24
views
How can Autofac implement attribute-based property injection?
To implement attribute-based dependency injection in a C# console application using Autofac, and to specify that this attribute should inject an object with the key "xxx", how should I do it?...
0
votes
0
answers
32
views
Attempt by security transparent method Autofac.Integration.Mvc.RegistrationExtensions
Attempt by security transparent method
Autofac.Integration.Mvc.RegistrationExtensions.RegisterControllers(Autofac.ContainerBuilder, System.Reflection.Assembly[])' to access security critical type '...
0
votes
0
answers
20
views
Autofac 8.0 throws error on IIndex<dataprovider, func<IDbContext>>
Actual class and its registration shown in below block
Repository with passing param as IIndex
public CycleDetailsMaintenanceRepositoryProvider(IIndex<DataProvider, Func<IDbContext>> ...
0
votes
0
answers
53
views
Runtime registration, register a new instance on runtime. (autofac)
I use DI to decouple some services from the rest of the application. I register them at the composition root of the project and read their configurations from the database. I would like to implement a ...
0
votes
0
answers
39
views
Autofac delegate factory with optional parameters
I am trying to create a delegate factory in autofac that allows for some parameters to be avoided. My idea is to register a class with registration parameters and be able to override it in the ...
0
votes
2
answers
84
views
Autofac: How to register dynamically register concrete types with generic with their own interfaces with generic type
AutoFac newbie here! I have a couple of types which take a generic, each with their own interfaces which take the same generic. Eg:
public class Foo<T> : IFoo<T>
{
...
}
public class ...
0
votes
0
answers
26
views
TypeInitializationException in OwnedInstanceRegistrationSource for MAUI Release Android
I have MAUI application which works fine in debug mode, but in release it throws such exception:
System.TypeInitializationException: TypeInitialization_Type, Autofac.Core.ImplicitRegistrationSource
...
1
vote
1
answer
73
views
Autofac: how to prevent disposing service registered through ServiceCollection?
If I will register all services through ServiceCollection then I get capability for switching between different DI implementations that reused this collection: Autofac, Simple Injector, or Microsoft....
0
votes
1
answer
134
views
How to use Typed IHttpClientFactory with Autofac (using .NET 8)?
I am trying to use Typed HttpClient with Autofac. But I couldn't able to make it work.
public class MainViewModel
{
public MainViewModel(MoviesApiClient moviesApiClient, IHttpClientFactory ...
-1
votes
1
answer
62
views
C# Dependency Injection from inheritence
Ive seen perviously the implementation of without explicitely injecting interface, when creating an interface can simply inherit for example Interface "IamContainerRegistered" and on compile ...
2
votes
3
answers
272
views
Autofac Access the IoC container in .NET MAUI
I wanted to configure Autofac for my .NET MAUI project which I was able to do, now the thing is I would like to access the IoC container so I can manually resolve dependencies if needed for setting up ...
0
votes
0
answers
86
views
Migrating AutoFac 4.9.1 to Autofac 8.0.0
Recently I am migrating Autofac 4.9.1 to Autofac 8.
Target framework is dotnet framework 4.8. I am facing issue while injecting Logger.
In older version I have LoggerModule module which is responsible ...
0
votes
0
answers
248
views
AutoFac Lifetime scopes for Isolated Azure Functions
We are looking to migrate several existing Azure Function apps that use AutoFac for DI from the in-process model to the isolated model.
As part of our current apps, we have some code taken from this ...
3
votes
1
answer
809
views
Using Autofac with HostApplicationBuilder
I am building a new .net 8 worker service and microsoft has modified the generic host. MSDN
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<...
0
votes
1
answer
56
views
Autofac: Registering a Singleton and InstancePerDependency Dependency Relationship
I'm using Autofac for dependency injection in my .NET application. I have a scenario where I want to register a service as a singleton and its dependency as InstancePerDependency. Here's a simplified ...
0
votes
1
answer
73
views
Scoped services via delegate factories in singleton services with autofac
I've found some unexpected behavior in Autofac related to resolving scoped services via delegate factories, from within singleton services. Is the following behavior expected or am I misunderstanding ...
0
votes
1
answer
214
views
How to implement Chain of Responsibility design pattern using Autofac
I am trying to implement a chain of responsibility design pattern using Autofac to wire everything up for dependency injection. When I run my sample project, I get a message from Autofac that the ...
0
votes
0
answers
72
views
How to go about catching controller activator exceptions in order to log them?
I have an asp.net framework 4.8 WebApi2 project and when I send a request to actions on a given controller I get a 500 error and the content shows it is due to a missing dependency. Quite correct, I'...
0
votes
0
answers
72
views
ASP.NET Core 6+, Autofac, TreeRouteBuilder costructor not found
I'm migrating from ASP.NET Core 2.2 to ASP.NET Core 8, and I have this problem.
To keep the code changes as minimum as possible, I'm using WebHost.CreateDefaultBuilder() passing a Startup class.
In ...
2
votes
1
answer
95
views
Get a collection of all IOptions objects with autofac
I'd like to be able to get a collection of all IOptions<T> registered in autofac so that I can save them to a custom JSON file. Something like:
class OptionsManager(IEnumerable IOptions)
I don'...
0
votes
1
answer
59
views
autofac - Not able to use EnableClassInterceptors with expression registration or lambda registration techniuqe
Below is my normal registration line for the Service and it was working fine till now. I have to use EnableClassInterceptors and I can't use EnableInterfaceInterceptors because of reason provided here ...
-1
votes
1
answer
177
views
How to mock IProcess to in a c# Unit test
I have a C# method I want to mock the return value of in a unit test. My test infrastructure uses Autofac and AutoMock for dependency inversion/injection.
public System.Diagnostics.Abstractions....
0
votes
3
answers
408
views
Hangfire & Autofac.Core.Registration.ComponentNotRegisteredException: The requested service has not been registered
I'm trying to set up Hangfire to execute a method in a service on a recurring basis.
However, the AutoFac is complaining that the service is not registered:
program.cs
var serviceCollection = new ...
0
votes
0
answers
76
views
Register assembly types as self and as specific interface
I'm trying to register types as self and as one interface.
When I add As<ICustomScreenDef> I cannot access concrete types any more. However if I use AsImplementedInterfaces() accessing concrete ...