Questions tagged [autofac]

Autofac is an inversion of control (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.

The Autofac project pages can be found here. For questions and support requests you can use the tag here at Stack Overflow.


Autofac keeps out of your way and places as few constraints on your design as possible.

Zero Intrusion: Components don't need to reference Autofac.

Simple Extension Points: Activation events like OnActivating(e => e.Instance.Start()) can achieve a lot of customisation in very little code.

Robust Resource Management: Autofac takes on the burden of tracking disposable components to ensure that resources are released when they should be.

Multiple Services per Component: Fine-grained interfaces are great for controlling dependencies. Autofac allows one component to provide multiple services.

Flexible Module System: Strike a balance between the deployment-time benefits of XML configuration and the clarity of C# code with Autofac modules.

Installation: Autofac can most easily be installed through its NuGet package.

Links

4295 questions
2
votes
1 answer

Need guidance on Autofac custom lifetimescopes vs. multi tenancy

Scenario: I need to provide different interface implementations to the same interface definitions within the same web application (appdomain) but to different "scopes". Imagine a simple hierarchical web content structure like this (if you are not…
lapsus
  • 2,915
  • 2
  • 32
  • 61
2
votes
0 answers

Orchard CMS. IAutofacActionFilter

I need to inject services into WebApi Action Filter (or into DelegatingHandler). With Autofac I can use IAutofacActionFilter (https://code.google.com/p/autofac/wiki/WebApiIntegration). But there isn't Autofac's WebApi Dependecy Resolver in the…
Aries
  • 128
  • 5
2
votes
0 answers

Autofac Injection by Caller Type

Is it possible to inject type to using autofac by the caller type? I have 2 objects that holds the same member type. What I want is when Container1 is called Autofac resolve IRegisteredType as RegisteredType with one value as the name parameter on…
Roi Shabtai
  • 2,981
  • 2
  • 31
  • 47
2
votes
1 answer

Inject Specific Type With Autofac

I want to inject specific type when some conditions are met. For example, i have got an interface like below. public interface IMyInterface{ } And also two classes that implement this interface public class MyClassA : IMyInterface { } and public…
2
votes
1 answer

Webapi DefaultHttpControllerSelector does not properly resolve my controller

I have an WebApi application that contains some controllers (they are registered using the extension method RegisterApiControllers). This application references another assembly that contains other controllers that I don't want to expose(I have…
Dave
  • 1,835
  • 4
  • 26
  • 44
2
votes
1 answer

Autofac 2.6 and Orchard 1.6 - Action Filter construction injection

To begin with two things. I am trying to achieve an action filter that logs when and action begins and when it end I am well aware of the .AsActionFilter() method in Autofac 3.0 BUT... The project that this is using is based in Orchard 1.6 which…
2
votes
4 answers

Autofac: how to inject properties with dynamic values?

By Autofac, it's easy to inject a static value to the CurrentDate property to instances of classes in a given assembly: builder.RegisterApiControllers(asm).WithProperty("CurrentDate", new DateTime(2012, 1, 13)); However, how to inject dynamic…
Zach
  • 5,715
  • 12
  • 47
  • 62
2
votes
1 answer

Consuming WebApi from Mvc Controllers - HttpClient or reference API assembly?

I have a solution with an MVC application and a Web API. They're in separate projects and domains (using CORS). I built it as a Web API to have the flexibility for adding consumers but currently my MVC application is the only consumer. As such I'm…
parliament
  • 21,544
  • 38
  • 148
  • 238
2
votes
1 answer

Autofac: adding a decorator to a delegate registration that takes parameters

I'm trying to manage registration of my WCF clients using autofac. I need to resolve Func, so I had registered the service using: builder.Register((c, p) => FooService(c,…
2
votes
1 answer

How to configure autofac to inject a type for an interface when initializing a Web API controller?

I have a WebAPI Controller which has a dependency on another class: public class HealthCheckController : System.Web.Http.ApiController { private readonly IHealthCheckReport _healthCheckReport; public…
The Light
  • 26,341
  • 62
  • 176
  • 258
2
votes
1 answer

Autofac: Custom LifetimeScope

I'm building a multi-tenant MVC 4 application and using Autofac as the container. I've been looking at the Autofac MultiTenant library, however unless I have missed something I don't think it really fits what I need. This is my situation: I don't…
2
votes
1 answer

Resolve Autofac factory based on multiple constructors

Does anybody know what's missing to make this test work? It's a pitty that it doesn't work out of the box. class A { } class B { public B(A a) { } } class C { public C(B b) { } } [Test] public void SuperFactoryResolutionTest() { var builder…
Marko
  • 5,437
  • 4
  • 28
  • 47
2
votes
1 answer

Exception when starting endpoint via NServiceBus.Host.exe

I am working on a sample message handler service using NServiceBus in a .NET 4.5 project. It works fine as long as DefaultBuilder is used. To configure the container for other services with Autofac as soon as reference to Autofac is added and…
amit_g
  • 30,880
  • 8
  • 61
  • 118
2
votes
2 answers

LINQ not working on IEnumerable

I'm using Autofac (I've registered the base nuget package in a console app) and want to take a look at a list of registrations. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using…
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108
2
votes
1 answer

Property injection into custom WebViewPage using Autofac

I'm creating an internal application framework that other dev teams in our organisation will use to build MVC applications from. As part of that, I'm creating the menu structure for all views, that is read from configuration and modified based on…
levelnis
  • 7,665
  • 6
  • 37
  • 61
1 2 3
99
100