tagged [autofac]

Automatically bind interfaces using AutoFac

Automatically bind interfaces using AutoFac I have some classes like UserQuery, CustomerQuery implementing interfaces like IUserQuery, ICustomerQuery respectively. In my binding configuration I need t...

30 Jan at 12:22

How do you do dependency injection with AutoFac and OWIN?

How do you do dependency injection with AutoFac and OWIN? This is for MVC5 and the new pipeline. I cannot find a good example anywhere. ``` public static void ConfigureIoc(IAppBuilder app) { var bui...

Using Autofac to inject a dependency into the Main entry point in a console app

Using Autofac to inject a dependency into the Main entry point in a console app Say I have a simple console application: What is the simplest way I can use Autofac to inject the Log instance and ensur...

13 Feb at 00:34

Resolving Hangfire dependencies/HttpContext in .NET Core Startup

Resolving Hangfire dependencies/HttpContext in .NET Core Startup I've installed and configured Hangfire in my .NET Core web application's Startup class as follows (with a lot of the non-Hangfire code ...

How to get Microsoft.Extensions.Logging<T> in console application using Serilog and AutoFac?

How to get Microsoft.Extensions.Logging in console application using Serilog and AutoFac? We have common BL classes in a ASP.NET Core application that get in the ctor: `Microsoft.Extensions.Logging.IL...

Autofac Scanning Assemblies for certain class type

Autofac Scanning Assemblies for certain class type I've started using `Autofac` and want to scan some DLL's and get `Autofac` to register some of the classes within them. The classes that I'm interest...

19 May at 04:11

How to resolve interface based on service where it's passed to

How to resolve interface based on service where it's passed to I have an interface. and two implementations (SomeImpl1 and SomeImpl2): I also have two services where I inject ISomeInterface (via contr...

7 Jul at 18:9

Resolving Generic Interface with Autofac

Resolving Generic Interface with Autofac Given the following code, how do I resolve the right SomeInstance in autofac? ``` public class BaseClass {} public class SubClass1 : BaseClass {} public class ...

27 Jul at 17:28

Register Dependencies in another Project

Register Dependencies in another Project My Models and DataContext are in another project to my Web MVC project in my solution. When I try to register my DataContext inside `AppHost` `Configure` metho...

26 Mar at 15:34

Return same instance for multiple interfaces

Return same instance for multiple interfaces I'm registering components with the following code: ``` StandardKernel kernel = new StandardKernel(); string currentDirectory = Path.GetDirectoryName(GetTy...

30 Jan at 15:22

autofac's Func<T> to resolve named service

autofac's Func to resolve named service Given registered services: Can I retrieve named implementations of `IFoo` interface by injecting something like `Func` ? ``` public class SomeClass

Register partically closed generic type with Autofac

Register partically closed generic type with Autofac I have `UnitofWork` class and it implement `IUnitOfWork`. I try to register that with Autofac: Implementation is: ``` public class UnitOfWork : IUn...

28 Feb at 13:36

Does autofac supports the new Web Api 2

Does autofac supports the new Web Api 2 I'm developing a web api as part of a MVC/API ASP.NET on VS 2013, MVC 5, API 2, but my `AutofacWebApiDependencyResolver` throws an exception every time I try to...

Is it possible to remove an existing registration from Autofac container builder?

Is it possible to remove an existing registration from Autofac container builder? Something along those lines: ``` builder.RegisterType().As(); builder.RegisterType().As(); builder.DeRegisterType().As...

13 May at 15:12

Autofac test all registered types can be resolved

Autofac test all registered types can be resolved I have a bunch of types registered with Autofac and some of the dependencies are rather deep. Is there a built in way to test that I can resolve all r...

30 Jul at 17:51

Autofac: Batch registration of open-generic types

Autofac: Batch registration of open-generic types I got an assembly with many concrete types that implement `IHandler`, such as the following: Currently, I'm registering the

Unable to cast object of type ServiceCollection to type 'Autofac.ContainerBuilder' using dotnet core and autofac

Unable to cast object of type ServiceCollection to type 'Autofac.ContainerBuilder' using dotnet core and autofac I am trying to use `autofac` in my `dotnet core 3.1` project, but I am unable to run pr...

28 Apr at 19:48

How to call async method in Autofac registration?

How to call async method in Autofac registration? I want to do call an `awaitable async` method during a registration like this: ``` // builder variable contains Autofac ContainerBuilder builder.Regis...

7 Jul at 10:22

Register a decorator in autofac without manually specifying all dependencies

Register a decorator in autofac without manually specifying all dependencies I have a decorator that has some other dependencies that should also be resolved using the container. Example: I can regist...

'ConfigureServices returning a System.IServiceProvider isn't supported.'

'ConfigureServices returning a System.IServiceProvider isn't supported.' I need ti use this `AutoFac` in ASP core 3.0 When I use this code in startu up: It show me this error: > 'ConfigureServices ret...

Using autofac with moq

Using autofac with moq I need to register my Autofac container with specific interface, for this case I want to resolved mock. How can I do it? I've tried: I don't want to change my c

4 Mar at 15:44

Registering implementations of base class with Autofac to pass in via IEnumerable

Registering implementations of base class with Autofac to pass in via IEnumerable I have a base class, and a series of other classes inheriting from this: > public abstract class Animal { }public clas...

Hangfire dependency injection lifetime scope

Hangfire dependency injection lifetime scope I'm rewriting this entire question because I realize the cause, but still need a solution: I have a recurring job in Hangfire that runs every minute and ch...

15 Jan at 20:50

Servicestack with Autofac not resolving IRequestContext

Servicestack with Autofac not resolving IRequestContext I am trying to use the Cache facilities of Service Stack. These are accessed through the RequestContext, which is injected by the IOC in your Se...

Property Injection for Base Controller Class

Property Injection for Base Controller Class I'm trying to automatically set a property on any controller that derives from my `BaseController` class. Here is the code in my `Application_Start` method...