Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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 ...
Tony's user avatar
  • 33
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 ...
stefan's user avatar
  • 158
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 } ...
Stelios Adamantidis's user avatar
0 votes
1 answer
256 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 ...
rjs52's user avatar
  • 39
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 (...
Jan Johansson's user avatar
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. ...
Wiesław Śruta's user avatar
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 ...
user24500090's user avatar
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....
SushiCode's user avatar
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 ...
Sohrab Sardari's user avatar
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....
Andrey Bushman's user avatar
-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 ...
lanes123's user avatar
  • 147
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<...
Mindbane's user avatar
  • 596
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 ...
Will's user avatar
  • 2,458
0 votes
0 answers
75 views

Error constructing handler for request of type Mediat.RequestHandler 2. Issue with Autofac or Mediatr?

First of all, I am aware that this error is very generic and there exists many such posts with similar error on stack overflow but still I am unable to overcome this issue. First of all the strange ...
Abhishek Singh Rana's user avatar
0 votes
2 answers
288 views

injecting a service into a queue consumer using MassTransit

I have a consumer that is configured like follows .ConfigureServices((hostContext, services) => { services.AddMassTransit(cfg => { cfg.AddConsumer <Consumers>(); ...
blu3f1rest0rm's user avatar
0 votes
1 answer
34 views

Resolving complex named type in Autofac

//I am trying to resolve a complex named type in Autofac which is getting resolved properly and //easily in Unitycontainer. But facing issues //I tried the following //I have a mail MailTopic class ...
ravikiran reddy's user avatar
0 votes
1 answer
235 views

Unable to resolve service for type 'Business.Abstract.IAuthService' while attempting to activate 'WebAPI.Controllers.AuthController'

First of all I'm try to use n-layer architecture in my dotnet project. Here is my error message: Unable to resolve service for type 'Business.Abstract.IAuthService' while attempting to activate '...
Alp Emre Elmas's user avatar
0 votes
1 answer
71 views

What is meaning of `key` in autofac configuration file?

What is key in configuration file? I found the special term in autofac configuration file, but I do not know, what is the meaning of that? and when I have to use that? { "components": [{ ...
sorosh_sabz's user avatar
  • 2,953
0 votes
2 answers
49 views

How can I use orderby on ContainerBuilder.RegisterAssemblyTypes?

I have 2 service classes both ending with Service: TurnoverGroupWebService & CashregisterTurnoverGroupWebService. These two classes are supposed to be automatically registered as ...
J. Rahmati's user avatar
1 vote
1 answer
44 views

Does Autofac Multitenant container works with IIndex<Key, Value>?

In my WPF app I use Multitenancy (2 tenants). To simplify question, I'll show example: var builder = new ContainerBuilder(); builder.RegisterModule<Module1>(); var container = builder....
HelloWorld's user avatar
0 votes
0 answers
139 views

Check if autofac module is already registered?

In our (huge, rather unmanageable) configuration there are many modules. One of them is vital for another module to function as expected, but may also be problematic to register twice (I know, this is ...
Anders Sewerin Johansen's user avatar
0 votes
1 answer
328 views

Autofac ContainerBuilder.Populate() will not accept a ServiceCollection

I'm trying to do the following so that I can add HttpClient configs to a service collection. This is a .NET 4.8 Windows Service Application. I get the error shown in the image. How might I accomplish ...
gilpach's user avatar
  • 1,385
0 votes
2 answers
1k views

DelegatingHandler Dependency Injection

I have a class AuthorizationHandler that is derived from System.Net.Http.DelegatingHandler. It has a DI constuctor and overrides the SendAsync method to retrieve an authorization token from ...
Griffin's user avatar
  • 842
0 votes
0 answers
301 views

Want to register hosted background service through Autofac in ASP.NET Core

I have tried to register a background service through Autofac, but my code is not able to resolve the dependency. If anyone did the same thing, please paste the answer here. I try to register the ...
kajal sharma's user avatar
5 votes
0 answers
77 views

How to Prevent Nested Decorators in Autofac When Using Interface Inheritance?

I have a .NET 7.0 application where I am using Autofac as my DI container. I have two interfaces IReadonlyRepository<T> and IRepository<T>, where IRepository<T> inherits from ...
snowfrogdev's user avatar
  • 6,843
0 votes
1 answer
68 views

Autofac WhenInjectInto like Grace/Ninject

i have this implementation with Grace (it's the same in Ninject) but i need use then in Autofac but autofac does not have a "WhenInjectInto" functionality. How can i migrate this code? Thx ...
avechuche's user avatar
  • 1,550
0 votes
1 answer
120 views

Is there a way to have a single instance of a service per an instance of another service without Owned<T>?

I'm writing a desktop application in C# and using Autofac for DI. In my app I want to have a big service that depends on several smaller services that depend on each other. There should be only one ...
aelsi2's user avatar
  • 11
1 vote
0 answers
43 views

C# Autofac. Parameters for dependency at resolution time

I'm using Autofac as IoC container and I want to resolve with parameters at resolution time. But I want to pass arguments to a dependency of resolution tree not to the class that I call on Resolve ...
JuanDYB's user avatar
  • 734
0 votes
2 answers
151 views

How to register multiple instances of same class

I am trying to register two instances of the same class but both instances end up share the same parameter values. I have registered the following in my startup.cs: using Autofac; using Autofac....
jtmaps's user avatar
  • 23
3 votes
1 answer
796 views

How to use Autofac / Castle DynamicProxy interceptors in ASP.NET Core 6?

I'm implementing an ASP.NET Core 6 service. I'd like to implement an interceptor, chose Autofac based on earlier experience. However, my interceptor is never executed. Here's my DI configuration code ...
balintn's user avatar
  • 1,393
0 votes
1 answer
2k views

Custom lifetime scope per request in ASP.NET Core without DependencyResolver

I am in the process of migrating a ASP.NET MVC (net48) application to ASP.NET Core (net6+). In this application we make heavy use of tagged autofac scopes. In net48 we used the ...
Ronny John's user avatar
0 votes
0 answers
31 views

Resolve a service using Autofac

Im quite lost here guys, there's this plugin for a gameserver (https://github.com/EvolutionPlugins/Dummy/blob/openmod/Dummy/Services/DummyProvider.cs) which i need to access all the tasks from the ...
Lautaro De la Puente's user avatar
0 votes
1 answer
161 views

Why cannot I resolve keyed registrations from lifetime scope?

I'm trying to resolve keyed service from a lifetime scope. The following code presents the issue: public class Service1 : IService1 { } public interface IService1 { } public class Service2 : ...
Spook's user avatar
  • 25.9k
0 votes
2 answers
1k views

Modular Monolith and Dependency Injection

I am currently struggling with dependency registration in my modular monolith with an ASP.NET Core 7 API. Each of the modules requires a blob storage service. For this blob storage service, I have an ...
timnot90's user avatar
  • 371
1 vote
2 answers
153 views

Dependency Injector and choosing the a class at runtime

My simple application could, using dependency injection, log something one way or the other way. Each logger is a class, derived from an interface ILogger. The class LoggerFactory decides which logger ...
Valmont's user avatar
  • 378
0 votes
1 answer
50 views

Autofac: How to control which instance gets sent to a dependency during an internal resolution chain?

I have these classes: Public Class ProcessRunner Implements IProcessRunner Public Sub New(Command As ICommand) End Sub End Class Public Class Command Implements ICommand Public Sub New(...
InteXX's user avatar
  • 6,357
2 votes
1 answer
4k views

How to use IHttpClientFactory with .NET 4.8 without using DI from .NET Core/Standard

I've got a .NET 4.8 windows forms app which uses Autofac for DI. Currently, we're using a single HttpClient instance which is registered as a singleton: builder.Register(c => { var ...
Luis Abreu's user avatar
  • 4,414
0 votes
2 answers
561 views

How to inject NLog using Autofac

I'm writing a WinForm App using Autofac and NLog. And so I created an interface: namespace BookShopApp.Logging { public interface ILoggerService<T> where T : class { void Info(...
AlexSn2020's user avatar
1 vote
1 answer
50 views

I can't inject my IUnitOfWork class into my ApartmentManager class

I'm building an apartment dues management system. Below are my related classes. If I inject my IUnitOfWork class in my ApartmentManager class and pass it in ctor it gives the following error. mistake: ...
nikki's user avatar
  • 37
0 votes
1 answer
325 views

Autofac: how to register/resolve a type whose constructor takes an abstract type as its parameter?

I have two concrete classes that inherit from an abstract class: Public Class UpdateCommand Inherits BaseCommand Implements IUpdateCommand Public Sub New(Root As DirectoryInfo) MyBase.New(...
InteXX's user avatar
  • 6,357
0 votes
1 answer
153 views

Autofac: how to register and resolve a type whose constructor requires a DirectoryInfo object?

I'm trying to do something which I suspect is pretty basic in Autofac (I'm just getting started on IoC/DI concepts and I'm still very wobbly-kneed), but I'm running into dead-ends. Any similar info I'...
InteXX's user avatar
  • 6,357
0 votes
1 answer
827 views

How to avoid memory leaks with Autofac?

I'm trying to better understand IoC/DI, in particular the concept of scopes. I'm using a sample WPF app (repo here) from a Pluralsight course (great service, BTW) and modifying it slightly. Naturally, ...
InteXX's user avatar
  • 6,357
0 votes
1 answer
477 views

Is it the best practice to inject ILifetimeScope to the constructor?

I'm using static function Resolve() in ILifetimeScope instance injected from constructor. private readonly ILifetimeScope _container; public MyService(ILifetimeScope container) { _container = ...
Masuri's user avatar
  • 1,126
1 vote
1 answer
251 views

How to Resolve ILogger in Autofac container

I am trying to replace dryIOC container with autofac container for some reason but I don't know the exact syntax how could I resolve ILogger uisng autofac Here is how I register ILogger in DryIoc ...
Marcelll's user avatar
0 votes
0 answers
49 views

AutoFac get multiple instances of same service injected but constructed differently

Is it possible to resolve multiple instances of the same service registered for an interface but constructed with different parameters? For example, I have a Interface and Service: public interface ...
smk081's user avatar
  • 1,115
0 votes
0 answers
100 views

Convert to use dependency injection?

I have the following example code: namespace ConsoleApp3 { public interface IPriceList { double GetPrice(); } public class PriceList : IPriceList { public double ...
OlavT's user avatar
  • 2,666
0 votes
2 answers
45 views

Why can Autofac not create this class that takes a non-generic implementation of a generic interface as a constructor parameter?

Using Autofac for injection. Given interface IStateMachine<TState, TTrigger> { } class ConcreteStateMachine : IStateMachine<MachineState, Trigger> { } builder.RegisterType<...
Lempface's user avatar
0 votes
0 answers
65 views

What do I do if I have multiple components?

I just started using Autofac. How do I register multiple components? I see this in the QuickStart guide: private static IContainer Container { get; set; } . . . var builder = new ContainerBuilder(); ...
BigSargeNCharge's user avatar
1 vote
1 answer
230 views

Autofac - How to access IRegistrationBuilder from IResolvePipelineBuilder & ResolveRequestContext?

I would like to extend my service registration [e.g. EnableInterfaceInterceptors] from Autofac Pipeline. However, I couldn't find a way to achieve that. Is there any entrypoint for me to access the ...
mannok's user avatar
  • 1,851
1 vote
1 answer
204 views

Autofac.Core.Registration.ComponentNotRegisteredException even the interface seems to be registered

I try to implement a WPF application using dependency injection and the MVVM pattern using the frameworks "CommunityFramework.MVVM" and "Autofac". What I have so far is the the ...
KingSB's user avatar
  • 58

1
2 3 4 5
25