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

How can I make Autofac inject different uniquely initialized instances of the same class to different controllers?

I have 2 controllers, both require an object of the MySettings type which represents a set of settings. Each controller needs its custom set of settings. In order to do that at the registration of the module I create 2 settings objects by hand and…
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
2
votes
1 answer

Autofac, WebAPI, and Media Formatters

I need some assistance. I am trying to use Autofac to get me a few dependencies that are need for a custom media formatter. I followed the Wiki but it is a little confusing. I am trying to use property injection for the media formatter since it…
Jamie
  • 3,094
  • 1
  • 18
  • 28
2
votes
2 answers

How would I use Autofac as the primary container in Catel?

Is there a way I can use Autofac as my primary container for Catel? I've seen that there is support for Unity, Ninject, MEF, Windsor, and Unity, but there is no mention of Autofac integration.
Damian
  • 2,709
  • 2
  • 29
  • 40
2
votes
1 answer

property injection using autofac 3.1.1

i am trying to inject through property in the following service, if I try constructor injection it works but I want to do property injection, what am I missing? public class SodaService { public ISoda _s; //public SodaService(ISoda s)…
zsri
  • 43
  • 1
  • 5
2
votes
2 answers

Customize container configuration with command line arguments

I have a .NET 4.0, WPF app which uses Caliburn 1.5.2 e Autofac 3.0.2. I want to use command line arguments to customize the building of the IoC container. The problem is that the command line arguments are only available at Appplication.OnStartup…
Arthur Nunes
  • 6,718
  • 7
  • 33
  • 46
2
votes
1 answer

How to resolve the correct type from the container (static type vs runtime type)?

I have a problem with resolving a dependency in autofac. It may be related to co/contra variance on type. The following program returns 0, 1. Which means that the two call to resolve does not returns the same types (whhereas it is the same object…
Dave
  • 1,835
  • 4
  • 26
  • 44
2
votes
2 answers

How to using container.Resolve in Module?

I am beginner with Autofac. Does anyone know How to using container.Resolve in Module? public class MyClass { public bool Test(Type type) { if( type.Name.Begin("My") ) return true; return false; } } public class MyModule1…
Flash
  • 1,615
  • 4
  • 17
  • 23
2
votes
0 answers

Change CacheManager from PerRequestCacheManager to MemoryCacheManager

In Nopcommerce an implementation of an interface ICacheManager is injected into objects that use Caching. One of such classes is CategoryService public partial class CategoryService : ICategoryService { private readonly ICacheManager…
Mathias F
  • 15,906
  • 22
  • 89
  • 159
2
votes
1 answer

Registering Partial Open Generics with Autofac

I have the below situation where the class implementing my interface takes multiple generics but only uses one of them in its implementation of the interface (the other is closed) .... public interface ITest { } public…
Levitron
  • 1,033
  • 9
  • 14
2
votes
2 answers

Autofac Func Resolution

I'm having issues with Autofac's (version 3.0.2) resolution of Funcs. Why is Autofac able to return Funcs for types which it cannot resolve? It seems Autofac is doing the dependency resolution when the func is executed which seems incorrect and…
smith324
  • 13,020
  • 9
  • 37
  • 58
2
votes
1 answer

Select multiple registrations for the same type in Autofac

I am developing a web app using MVC4 with Autofac. I have a global exception filter in which I'm injecting a logger service, so I'm initializing it in App_Start like this: public static void RegisterGlobalFilters(GlobalFilterCollection filters) …
valentin
  • 667
  • 2
  • 12
  • 19
2
votes
1 answer

Automapper with Multi-Tenant Application - How can we supply custom mapping rule per tenant?

We have a multi-tenant application - which is based on use AutoFac multi-tenancy add-in. We also use AutoMapper to do our domain to ViewModel mappings. We have now had requests for clients to have different mapping rule/formatting for their…
GraemeMiller
  • 11,973
  • 8
  • 57
  • 111
2
votes
1 answer

Autofac OwnedInstances and ASP.NET Web API's InstancePerApiRequest support

For my ASP.NET Web API project, I have the following set up which uses Autofac as the IoC container: protected void Application_Start(object sender, EventArgs e) { HttpConfiguration config = GlobalConfiguration.Configuration; …
2
votes
2 answers

Passing constructor arguments to injected objects in the MVC controller

I am developing a MVC application using .net, I am using autofac as the IoC container. I have service class which needs a parameter in the constructor. And the parameter is resolved at run time from the input URL. public interface IService { …
Stay Foolish
  • 3,636
  • 3
  • 26
  • 30
2
votes
1 answer

Meta broken in Autofac 3+?

I have some code that registers types with strongly typed metadata. It looks something like this: class Foo { } public interface IFooMetadata { int Position { get; } } [TestFixture] public class MyTestFixture { [Test] public void…
Matt Siebert
  • 367
  • 1
  • 9
1 2 3
99
100