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

Fire and Forget with un-managed resources

I'm using autofac in an owin-driven web api project. I've come to a place where I need to "Fire and Forget" some processing of data. This normally isn't an issue. But since the dependencies are controlled by the per-request lifetime scope managed…
calebboyd
  • 5,744
  • 2
  • 22
  • 32
2
votes
1 answer

Applying generic decorators conditionally in Autofac based on configuration values

I have an application with an command/handler based architecture. I have the following interface: public interface ICommandHandler { void Handle(TCommand command); } There are many non-generic implementations of this interface. Those…
Steven
  • 166,672
  • 24
  • 332
  • 435
2
votes
2 answers

The view found at was not created when Razor error occurs

I use MVC4 with mono 3.2.3 and I notice that if I create an error in Razor cshtml file: @for(int i = 0; i < 8aaaa; i++) Following error occurs: System.InvalidOperationException The view 'Index' or its master was not found or no view engine…
marxin
  • 715
  • 1
  • 10
  • 18
2
votes
2 answers

Multiple Registries FluentScheduler

I am using FluentScheduler, and have an issue where I have 2 Registry classes, FeedRegistry SitemapRegistry FeedRegistry is supposed to run every 15min, and sitemapregistry evey 6 hours. I have this code: TaskManager.Initialize(new…
Paul
  • 1,457
  • 1
  • 19
  • 36
2
votes
1 answer

Find out which module registered type

I'm debugging autofac issues in an application with quite a lot of modules. Is there a way to find out what module registered some registration? I'm looking at the ComponentRegistry of the container, but I can't find any information there. EDIT: A…
carlpett
  • 12,203
  • 5
  • 48
  • 82
2
votes
1 answer

Restrict dependency injection to project layer

I have an ASP.NET web project referencing a service layer class library. I am using dependency injection which I setup in the web layer. I want to take advantage of dependency injection in both projects. But I do not want the web layer to be able to…
Andrew
  • 5,525
  • 5
  • 36
  • 40
2
votes
2 answers

Build() or Update() can only be called once on a ContainerBuilder

We are currently using autofac in our mvc web app. Build() or Update() can only be called once on a ContainerBuilder Every 1-4 days we get the error noted above. It's driving me crazy. I've been trying to see why it would be doing this but I can't…
Prescient
  • 1,051
  • 3
  • 17
  • 42
2
votes
2 answers

How to use Autofac to register components in non referencing projects

Ho do you register components with Autofac without referencing all the projects in your web application? I have layered my application in the following format: Website Tasks Services Please use the code below for my explanations. My controller…
Brendan Vogt
  • 25,678
  • 37
  • 146
  • 234
2
votes
1 answer

What's the difference between Autofac.WebApi and Autofac.WebApi2?

What's the difference between Autofac.WebApi and Autofac.WebApi2? When I add the Autofac.WebApi2 NuGet Package I'm not able to add a "using Autofac.Integration.WebApi;".
Adam Mendoza
  • 5,419
  • 2
  • 25
  • 31
2
votes
1 answer

Configure Autofac Container for background thread

I have an asp.net MVC site which has many components registered using an InstancePerHttpRequest scope, however I also have a "background task" which will run every few hours which will not have an httpcontext. I would like to get an instance of my…
Paul
  • 1,457
  • 1
  • 19
  • 36
2
votes
1 answer

Autofac resolve based on class attribute / metadata

I want to register and resolve dynamically loaded types based on their class attribute. My code is as follows: The custom class attribute: [MetadataAttribute] public class FooIdentifier : Attribute { public string Identifier { get; private set;…
GerjanOnline
  • 1,871
  • 16
  • 17
2
votes
2 answers

MassTransit , Autofac and 2 bus instances

I have a situation with a publisher and consumer sitting in the same application. I'm using autofac. As I understand I need 2 Bus instances with 2 endpoints, one for publisher, one for subscriber. I'm using autofac but I don't know how to create 2…
Lev
  • 434
  • 2
  • 9
2
votes
1 answer

Autofac PropertiesAutowired - Is it possible to ignore a one or more properties?

Despite the advice to pass dependencies through the constructor I've found that the development cost of having parameterless constructors and then autowiring all of the properties on everything is significantly less and makes the application much…
satnhak
  • 9,407
  • 5
  • 63
  • 81
2
votes
2 answers

Eliminating IoC container coupling in factory

I have multiple, multilingual "websites" running under a single web application. Each "locale" has its own Solr core (with the same fields across all locales). I'm using SolrNet to perform my search queries. In order to switch cores on a per-request…
Ant P
  • 24,820
  • 5
  • 68
  • 105
2
votes
2 answers

MVC5 Autofac: The view found at was not created

I created very simple MVC 5.0 application that I push to GitHub repository: https://github.com/marxin/mvc-sample. My motivation is to execute app on Linux with mono 3.2.3. I would like to add Autofac NuGet package (more precisely 3.3.0), that works…
marxin
  • 715
  • 1
  • 10
  • 18