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

Can Autofac IStartable be used with NServiceBus when the startable component needs IBus?

The scenario here is that there is a component that needs to run some initialisation code on start-up. This is achieved by having the code implement Autofac.IStartable.Start and registering the code as IStartable. This code is then used in several…
Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
2
votes
2 answers

How to use Serilog with Raygun and Autofac differentiating between logs and errors

I'm trying to use Serilog with the Raygun sink using AutoFac I successfully configure Serilog with AutoFact using https://groups.google.com/forum/#!topic/serilog/R23B8CLso9Q If I want to log a trace/debug/info to a log rolling file ONLY and…
2
votes
1 answer

Issues with hangfire job activation and Autofac

I'm triying to implement hangfire in my projects. I have a issue when I add a RecurringJob to hangfire, when it's fired i get this error: Autofac.Core.Registration.ComponentNotRegisteredException The requested service …
Daniel
  • 137
  • 4
  • 10
2
votes
1 answer

AutoFac Exception after upgrading NServiceBus

I just upgraded NServiceBus from 4.6 to 5.0 I did the steps suggested in the "4 to 5" document and am able to compile. Now I receive the following Error: None of the constructors found with …
Ole Albers
  • 8,715
  • 10
  • 73
  • 166
2
votes
3 answers

How do I get Autofac delegate factories to work with obfuscation?

We're updating code to use Autofac. We'd like to use custom delegate types to define factories instead of Func's. But we also use an obfuscator, which renames parameters. We'd like to tell the Autofac container to match by type instead of name as…
Levi Drain
  • 445
  • 3
  • 10
2
votes
0 answers

Constructor resolve collection of generic interfaces using Autofac

I've got a lot of implementations of a specific generic interface and would like to resolve all of these implementations in the constructor. Of course, I can just add every implementation in the constructor. This will cause the constructor to have…
Jan_V
  • 4,244
  • 1
  • 40
  • 64
2
votes
0 answers

Call Initialize after simple ctor and after MVC parameters are bound

I am using autofac and MVC together to allow me to auto resolve view models. This works well although I have an issue where I need to call an Initializable method for every view model after it is resolved. I solved this issue by simply hooking into…
Ruskin
  • 1,504
  • 13
  • 25
2
votes
1 answer

Autofac With WCF Not Working

I'm trying to implement Autofac in WCF but it is not working . Step : 1 protected void Application_Start(object sender, EventArgs e) { var builder = new ContainerBuilder(); // Register your service implementations. …
pargan
  • 301
  • 3
  • 6
  • 19
2
votes
1 answer

Autofac throws File Not Found exception when registering Moq instance

I have created a Windows 8.1 App Store Unit Test project, added Moq and Autofac and tried to register a Mock with Autofac. When I invoke RegisterInstance(serviceMock.Object) it Autofac throws a File Not Found exception The interface…
Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102
2
votes
1 answer

Mocking Autofac's "Resolve" extension method with TypeMock

I'm trying to mock an Autofac resolve, such as using System; using Autofac; using TypeMock.ArrangeActAssert; class Program { static void Main(string[] args) { var inst = Isolate.Fake.Instance(); …
Lockshopr
  • 21
  • 4
2
votes
2 answers

AutoFac resolve interface for keyed registration

I am using AutoFac and am using the following lines in my registration two different clases implement the same interface with two different…
JohanLarsson
  • 475
  • 1
  • 8
  • 23
2
votes
2 answers

Autofac instance per viewmodel

I have a little problem with Autofac configuration. My goal is to create new EFContext per ViewModel Right now I have: ContainerBuilder builder = new ContainerBuilder(); builder.Register(ctx => new EFContext()) …
rraszewski
  • 1,135
  • 7
  • 21
2
votes
1 answer

Autofac: How to inject IPrincipal into Repository layer

I am designing an n-tier application using Repository Layer/Service Layer/Presentation Layer using c#.net web api and Autofac DI container. Here is my dilemma. I am trying to unit test my web api controllers but my repositories have a property…
user1790300
  • 2,143
  • 10
  • 54
  • 123
2
votes
2 answers

Different controllers with the same name in two different areas results in a routing conflict

I have two areas: ControlPanel and Patients. Both have a controller called ProblemsController that are similar in name only. The desired results would be routes that yield /controlpanel/problems =>…
moribvndvs
  • 42,191
  • 11
  • 135
  • 149
2
votes
3 answers

Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3

I have a Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3 I posted my issue to github https://github.com/autofac/Autofac/issues/572#issuecomment-63236738 and got response that I need to ask here :) Below my situation: What I have: // Setup DI as…