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
0 answers

Autofac attribute property injection not working

I checked these answers: Autofac attribute injection failing on attributes Autofac property injection is not working However, my code looks correctly set up but the property injection is not working. This is my Autofac registration: public static…
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
2
votes
1 answer

Proper way for property injection using Autofac

I'm building a MVC application with Autofac and EntityFramework. I have a large set of data repositories / business objects that use my logging interface (NLog). I have just started working with Autofac and would like to know the preferred way for…
Martin
  • 397
  • 3
  • 16
2
votes
1 answer

Create ViewModel instance immediatly with Autofac

I'm replacing MVVM Light default SimpleIOC with Autofac. So far so good, but now I'm trying to initialize one ViewModel as soon the app starts, as I need to register some calls with MessengerInstance, with SimpleIOC this was as easy as …
D.Rosado
  • 5,634
  • 3
  • 36
  • 56
2
votes
2 answers

Selectively intercepting methods using autofac and dynamicproxy2

I'm currently doing a bit of experimenting using Autofac-1.4.5.676, autofac contrib and castle DynamicProxy2. The goal is to create a coarse-grained profiler that can intercept calls to specific methods of a particular interface. The problem: I…
Mark Simpson
  • 23,245
  • 2
  • 44
  • 44
2
votes
0 answers

AutoFac double instances when resolving collections

I register services with the following code (used Autofac MVC integration package): // IoC var builder = new…
user2160375
2
votes
1 answer

Autofac - Instance Scope WCF

I'm using Autofac with WCF. My service (ExportWebService) needs to take in a dependancy (ExportService). I setup the ApplicationStart to do this: builder.Register(c => new ExportWebService(c.Resolve())); But when I do so I get the…
user472292
  • 1,069
  • 2
  • 22
  • 37
2
votes
1 answer

Autofac: Resolving dependencies with parameters

I'm currently learning the API for Autofac, and I'm trying to get my head around what seems to me like a very common use case. I have a class (for this simple example 'MasterOfPuppets') that has a dependency it receives via constructor injection…
2
votes
1 answer

Autofac not resolving Type and Named Parameter for ApiController

I have three different applications that all build with the same business layer/data layer. I'm adding a IUserNameProvider to the IUnitOfWork class that is used by all three applications. Because the each application get the User names using a…
Steve Wash
  • 986
  • 4
  • 23
  • 50
2
votes
2 answers

How to debug a dependency injection failure in published website

Recently I faced this problem where an ASP.Net MVC website with Autofac as DI was working fine in my local IIS but when I published it in Azure, it was not getting redirected to the default controller, instead it was showing me the welcome page. I…
ViBi
  • 515
  • 7
  • 19
2
votes
2 answers

How to define value of nested object at runtime in Autofac

Let's say I have the following hierarchy. class PersonWithJacket { public PersonWithJacket(Jacket jacket) { } } class Jacket { public Jacket(string brand) { } } I register these classes in my Autofac container …
Tobias
  • 4,999
  • 7
  • 34
  • 40
2
votes
1 answer

SingleInstance activation at container build

I have a SingleInstance service that I need to be active very early in my application. However, this service is maintained in a DLL that is consumed by other applications, so I'd prefer that this "early activation" be configured directly in the…
Marc L.
  • 3,296
  • 1
  • 32
  • 42
2
votes
1 answer

Autofac resolving parameters in runtime

Let's get straight. I have interface and class like this: public interface IDataBase { DataTable GetSomeTableData(); } My class: public class DataBase : IDataBase { private readonly string _connectionString; public DataBase(string…
2
votes
0 answers

connection string dependancy injection identity server v3

I am using Thinktecture Identity Server V3 and having issues working out how to make the dependancy registration use different connection strings for 2 different repositories. See code…
2
votes
1 answer

Register autofac in windows service project

I want to use autofac in my project for windows service but I get this error: "The requested service 'InsideView.Business.Services.BusinessServiceFactory' has not been registered. To avoid this exception, either register a component to provide the…
user1096760
  • 87
  • 2
  • 8
2
votes
2 answers

Issue using AutofacWebApiDependencyResolver with OWIN and WebAPI 2.1

I can't seem to use the DependencyResolver in my OAuthAuthorizationServerProvider. DependencyResolver.Current returns the MVC one which I don't use, and GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IXXX)) throws the…
Todd
  • 175
  • 7