autofac

Using Autofac for DI into WCF service hosted in ASP.NET application

I'm having trouble injecting services dependencies into my WCF service using Autofac 1.4.5. I've read and followed the Autofac wiki page on WcfIntegration but my debugging shows me that my WCF service is created by the System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance() method and not by the AutofacWebServiceHostFactory. What a...

How to resolve a named instance from a static class?

Does anyone have any idea about what i doing wrong? I have a such static class: public static class ApplicationContainer { private static ContainerBuilder builder = null; private static IContainer container = null; public static void Create() { builder = new ContainerBuilder(); builder.RegisterInstance...

Autofac - resolving component with parameters dynamically

I have a class that takes an interface as a constructor argument. There are two implementations of this interface and I want to decide what implementation to use at runtime based on a variable. The problem is that the class above is deep in an object heirarchy that is resolved by Autofac and so I can't pass in the argument. Somehing li...

Have to register every class before the autofac container can resolve?

let's say this scenario: public class B {}; public class C { public C(B b){} } To resolve C from Autofac container, I have to register both B and C to container. But, today I used Unity, it seems I just need to register B to container, then C can be resolved. So Autofac can't do as Unity do? ...

Autofac 2.2 and ASP.NET MVC 2.0 Areas support

Hi there! In his blog Nicholas announced support for ASP.NET MVC 2.0 Areas. However, I couldn't get it working and from what I see in Autofac sourcecode, areas support is nowhere to be seen. More specifically, RegisterControllers return builder.RegisterAssemblyTypes(controllerAssemblies) .Where(t => typeof(IController).IsAssignable...

Autofac different service resolution based on TypedParameter

Is there anyway to get autofac to resolve the service that has a concrete implementation with the constructor that matches a given parameter most specifically. By this i mean match a constructor for a child type instead of matching the constructor for the base type. For example i'd like to make the following test pass [TestFixture] pu...

Setting up behavior on a method appears to be calling the method

I posted this on the TypeMock forums, but am too impatient to wait for a response there. This is a very n00b question. I'm trying to set up a fake IContainer. Here's what I have: var container = Isolate.Fake.Instance<IContainer>(); var program = Isolate.Fake.Instance<IProgram>(); Isolate.WhenCalled(() => container.Resolve<IProgram...

Autofac in ASP.Net MVC

As a newbie to Autofac, I'm trying to figure out how to register my Repository for my Controllers. The Repository takes a web service in its constructor to communicate with the server. This application is multi-tenant and the tenant name is accessed in the MVC route data. Since I can't access the route data within global.asax like most...

How to learn Autofac fast for Windows development?

I'm about to start a project where the IoC being used is AutoFac - at a new company. I have no prior experience with DI/IoC and want to get up to speed on this so I don't look toooo unintelligent. This will be for a WPF application (which again I'm not too cluey about but that will be OK) What are some good resources I could use to lear...

How should I test an MVC web app in a container with nunit?

We have an MVC web which is running in Autofac. All the config is stored in an autofac config section in the web.config and when run the Global asax sets up the container and sorts out all the modules by providing them with their config settings - the one I'm interested in at the moment is the NHibernate module - so this gets the connec...

Implementing a generic service factory or provider in Autofac

I have an interface, for example ISomeService. ISomeService provides a common service, but the implementations may vary. As such, they will have different dependencies. Consider: interface ISomeService { void DoSomething(); } class SomeServiceA : ISomeService { public SomeServiceA(DependencyOne one, DependencyTwo two) ...

Autofac's named method

I'd like to identify some types using a service name. I need exactly what is showen in this example builder.RegisterAssemblyTypes(controllers) .Where(t => t.IsAssignableTo(typeof(IController)) .Named(t => "controller-" + t.Name.ToLower()); But the method named has no overload which takes one argument of type string(only the generic o...

Resolve generic service

I got the following service: IRepository<TEntity, TPrimaryKey> ..for which I've created an implementation defined as: Repository<TEntity, TPrimaryKey>. How do I register it in autofac so that I can resolve it as: IRepository<User, int> ...

Resolving dependency depending on generic type - Autofac

I have a generic class (GenericClass) which is having a dependency depending on the generic type (IGenericDependency). This dependency is also generic. public class GenericClass<T> { private readonly IGenericDependency; } The type parameter is not known until runtime. So far I've done this: I'm injecting a Func. public class...

Autofac with FluentValidation in MVC2

I'm getting a 'not registered error' during execution in the ValidatorFactory.CreateInstance call. It appears the type being sent into the method is correct. My registration code: ... builder.RegisterAssemblyTypes(assembly).Where(t => t.Name.EndsWith("Validator")).As<IValidator>(); builder.Register(d => _containerProvider).As<IContain...

Autofac - Service constructor takes reference to instantiating object.

How do I deal with: Current code looks like; class Class1 : ISomeInterface IFooService _service; void SomeMethod(){ _service = new FooService(this); ..... } class FooService : IFooService public FooService(ISomeInterface class1Implementer) { _class1Implementer = class1Implementer } I want...

DI (Autofac) in a plugin architecture: Is one separate DI container per plug-in OK?

I am trying to introduce DI (with Autofac) into an existing Windows Forms application. This application has a basic plug-in architecture where each plugin displays its own form. On startup, the application scans registered assemblies for types that implement IPlugin, and then activates these using Activator.CreateInstance: public inter...

In Autofac how do I change the instance that is registered after Build has been called?

So lets say i have this code var builder = new ContainerBuilder(); builder.RegisterInstance(new MyType()); var container = builder.Build(); Then some time later I want to change the instance of MyType for all future resolves that are called on container. ...

Injecting a service into an implementation of NHibernate's IUserType using Autofac.

I'm using NHibernate to map the following class to an Oracle database in my ASP.NET MVC application: public class User { // Needs to be encrypted/decrypted when persisting public virtual string Question { get; set; } } Following several examples that I've found, I would like to use an implementation of NHibernate's IUserType t...

Autofac - Register plugins

Hi all, i have an interface that defines some methods and i have N classes that implement it. How can i register all the classes found in all the loaded assemblies with autofac? ...