autofac

Autofac Session Scope

I am investigating the use of Autofac in our web application having previously used Castle Windsor in the past. The thing that I really like with Autofac is being able to express dynamic component construction through lamda expressions, as opposed to creating DependancyResolvers etc. in Windsor. One scenario I have is that I want a par...

Autofac: Resolve all instances of a Type

Given the following registrations builder.Register<A>().As<I>(); builder.Register<B>().As<I>(); builder.Register<C>().As<I>(); var container = builder.Build(); I am looking to resolve all instances of type I as a IEnumerable (Array or Collection it doesnt matter). In Windsor I would have written the following. foreach(I i in contai...

Does Autofac have a best practice for *optional* Xml configuration?

Background: I wanted to distribute a library to some other developers (something along the lines of an SDK or toolkit abstracting some internal web services). I'm using Autofac in order to inject different versions of the underlying services, mostly for stubbing. I want to distribute this assembly to a wide range of developers: users ...

Autofac with Open Generics and Type Specified at Runtime

The documentation states that Autofac supports open generics and I am able to register and resolve in a basic case like so: Registration: builder.RegisterGeneric(typeof(PassThroughFlattener<>)) .As(typeof(IFlattener<>)) .ContainerScoped(); Resolve: var flattener = _container.Resolve<IFlattener<Address>>(); The above ...

Autofac component registration/resolution bug?

I seem to have a problem - rather unexpected; so I guess I might be doing something silly/wrong. I register two container scoped services as such: builder.Register<IServiceInfo>(c => CreateServiceInfo(c)).As<IServiceInfo>(); builder.Register<IServiceInfo>(c => CreateServiceInfoSomeOther(c)).As<IServiceInfo>().Named("someOther"); Now ...

Manage autofac container setup

One of my team members decided to use autofac on one of our services and because we wanted to try it out we stuck with it. Now some time has passed and the container setup method has grown! It so big that we are having problems with it. Splitting it up did not bring the results we looked for. Maybe we are just using it wrong. So my ...

AutoFac Autowiring Conventions

StructureMap has the ability to apply conventions when scanning. Thus IFoo => Foo, without explicit registration. Is something simular available in AutoFac? Looked around and just can't find anything helpfull. Thanks, ...

NHibernate with Autofac within ASP.NET (MVC): ITransaction

What is the best approach to managing NHibernate transaction using Autofac within web application? My approach to session is builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()) .ContainerScoped(); For ITransaction, I have found an example on Google Code, but it relies on HttpContext.Current.Error when deciding wh...

Dependency injection into custom ViewPage generates weird error

i'm trying to inject stuff into a custom ViewPage (ModelViewPage, from MvcContrib) public class ValidatedModelViewPage<T> : ModelViewPage<T> where T : class { public ValidatedModelViewPage(IEnumerable<IBehavior<IMemberElement>> elementBehaviors) : base(elementBehaviors.ToArray()) { } } and my Autofac registr...

How do I implement a delegate factory?

The documentation for Autofac has an interesting page describing its ability to automatically generate delegate factories. It also strongly suggests that you can get similar results without Autofac by writing them by hand. I'm using Unity for IoC and would like to avoid passing the container around to objects that need to create other o...

How to pass controller's ModelState to my service constructor with Autofac?

I have a wrapper on ModelStateDictionary which all my services accept. Is it possible to configure the autofac to inject the controller ModelStateDictionary into the constructor of the wrapper and then inject it into service constructor? //code public class ModelValidation : IModelValidation { public ModelValidation(ModelStateDictionar...

Dependency Injection for Presenter

I have a Presenter that takes a Service and a View Contract as parameters in its constructor: public FooPresenter : IFooPresenter { private IFooView view; private readonly IFooService service; public FooPresenter(IFooView view, IFooService service) { this.view = view; this.service = service; } } I reso...

IOC/Autofac problem

I am currently using Autofac, but am open to commentary regarding other IOC containers as well. I would prefer a solution using Autofac if possible. I am also somewhat new to IOC so I may be grossly misunderstanding what I should be using an IOC container for. Basically, the situation is as follows: I have a topmost IOC container for m...

Good practices for handling multiple config files with DI frameworks

In my current solution I have 18 projects and most of them have their own configuration files (app.config or web.config). Each project uses single shared BLL assembly. I'm using Autofac to handle dependencies but haven't come with a decent way of managing my configuration. Configuration entries are roughly the same, but values are differ...

Autofac doesn't like MVC Source

I added the ASP.NET MVC 2 RC2 source code to my solution (using these instructions: http://blog.stevensanderson.com/2009/02/03/using-the-aspnet-mvc-source-code-to-debug-your-app/), but now it won't build because of an error from Autofac. The type 'System.Web.Mvc.IControllerFactory' is defined in an assembly that is not referenced. You m...

Autofac: How to limit the lifetime of an IDisposable object without passing around the IoC container

I'm currently learning how to use Autofac, and I'm stuck with disposing IDisposable objects deterministically. Let me first present the situation before I'll state my problem. Starting position: Let's say my object model is defined through the following interfaces: interface IApple : IDisposable { void Consume(); } interface IHor...

printable autofac documentation?

I can't seem to find anything printable about AutoFac ...

How to carry out custom initialisation with autofac

I'm adding autofac to an existing project and some of the service implementations require their Initialize method to be called and passed configuration information. Currently I'm using the code: builder.Register(context => { var service = new SqlTaxRateProvider( context.Resolve<IUserProvider>() )...

Registering Collections in Autofac 2.1.10 RC

I am upgrading code from Autofac 1.4 to 2.1.10 Release Candidate. My module previously performed registration like this: builder.RegisterCollection<IExceptionHandler>() .As<IEnumerable<IExceptionHandler>>() .FactoryScoped(); builder.Register<AspNetExceptionHandler>() .As<IExceptionHandler...

Customizing Autofac Controller registration

I am trying to use Autofac and Autofac.Integrations.Web to register ASP.NET MVC controllers. I am currently using assembly scanning to find the controllers but one of them needs a special parameter that I would prefer to pass in instead. Found below are the registrations I have tried. var builder = new ContainerBuilder(); builder.Regis...