autofac

Registering Controllers using AutoFac in an ASP.NET MVC2 application with Areas

Hi, Has anyone been able to get AutofacControllerFactory working in applications where the controllers are split into Areas? Looks like it is not supported out of the box in the current version. Thanks ...

Mocking Autofac's "Resolve" extension method with TypeMock

I'm trying to mock an Autofac resolve, such as using System; using Autofac; using TypeMock.ArrangeActAssert; class Program { static void Main(string[] args) { var inst = Isolate.Fake.Instance<IContainer>(); Isolate.Fake.StaticMethods(typeof(ResolutionExtensions), Members.ReturnNulls); Isolate.WhenCalled(...

Simple Inversion of Control framework for Java/Scala

I am looking for a simple to use IoC container for GUI applications written in Java/Scala. It should support Convention over Configuration, lifecycle management, configuration in code (preferably without any XML needed at all), and checking dependencies at compile-time as much as possible. Something similar to Autofac would be perfect....

Autofac configuration validation

Does Autofac have an equivalent to StructureMap's AssertConfigurationIsValid method? Or does configuration validation occur when creating the container? I believe the AssertConfigurationIsValid method checks that the container can create all the configured services. Obviously it can't pick up more subtle configuration mistakes - related...

Adding IoC Support to my WCF service hosted in a windows service (Autofac)

I'd like to setup my WCF services to use an IoC Container. There's an article in the Autofac wiki about WCF integration, but it's showing just an integration with a service hosted in IIS. But my services are hosted in a windows service. Here I got an advice to hook up the opening event http://groups.google.com/group/autofac/browse_thr...

Managing NHibernate ISession with Autofac

Does anyone have any tips or best practices regarding how Autofac can help manage the NHibernate ISession Instance (in the case of an ASP.NET MVC application)? ...

Auto inject property for register types without DependencyAttribute.

Register<IA, A>(); class B { public IA A {get;set;}} //container inject this property because IA was registered In autofac you can do builder.RegisterType<A>().InjectProperties(); for this. Is there any extension for unity to do this? Or may be extension which I can use as sample for implement this feature by myself? ...

Error: The creation delegate must not return null in Autofac?

In my project I am using Autofac. Previously it was working fine. Now I have added some new code in Autofac and it's giving me "The creation delegate must not return null " error. The changes that I have made are as follows builder.Register<Rep>(c => { /*Get Session and LoginId*/ ...

How can autofac return service with constructor parameters?

Hello, I am testing out Autofac container with these below: var builder = new ContainerBuilder(); builder.Register(t => new TreatmentCenterRepository()) .As<IRepository<TreatmentCenter>>(); builder.Register(t => new CreateTreatmentCenterCommandHandler(t.Resolve<IRepository<TreatmentCenter>>())) .As<ICommandHandler<CreateTreatment...

autofac's Func<T> to resolve named service

Given registered services: builder.RegisterType<Foo1>().Named<IFoo>("one").As<IFoo>(); builder.RegisterType<Foo2>().Named<IFoo>("two").As<IFoo>(); builder.RegisterType<Foo3>().Named<IFoo>("three").As<IFoo>(); Can I retrieve named implementations of IFoo interface by injecting something like Func<string, IFoo> ? public class SomeClass...

MEF part unable to import Autofac autogenerated factory

This is a (to me) pretty weird problem, because it was already running perfectly but went completely south after some unrelated changes. I've got a Repository which imports in its constructor a list of IExtensions via Autofacs MEF integration. One of these extensions contains a backreference to the Repository as Lazy(Of IRepository) (la...

Resolving HttpRequestScoped Instances outside of a HttpRequest in Autofac

Suppose I have a dependency that is registered as HttpRequestScoped so there is only one instance per request. How could I resolve a dependency of the same type outside of an HttpRequest? For example: // Global.asax.cs Registration builder.Register(c => new MyDataContext(connString)).As<IDatabase>().HttpRequestScoped(); _containerProvi...

Resolving dependency on data model using Autofac

I have run into an issue while creating a data service and using Autofac WCF Integration to resolve a dependency on my data model. Registrations are of the form: builder.RegisterType<MyService>() .InstancePerDependency(); builder.RegisterType<MyModel>() .InstancePerLifetimeScope(); where MyModel has a dependenc...

What happened to Lazy<T> support in Autofac?

In beta builds of Autofac 2.1 there was support for automatic resolution of Lazy<T> as described in Nicholas Blumhardt's Lazing Around with Autofac blog post. The code still seems to be in the source on Google Code, but I can't find LazyDependencyModule in any of the .NET 4.0 binaries I've looked at. Has it moved somewhere else? How do...

How do you use Autofac to inject setters into your action filters in ASP.NET MVC2?

I thought this would do the trick in my Global.asax Application_Start, but it doesn't work: var builder = new ContainerBuilder(); builder.RegisterType<ExtensibleActionInvoker>().As<IActionInvoker>(); builder.RegisterControllers(Assembly.GetExecutingAssembly()).InjectActionInvoker(); What am I missing? ...

Making Custom IoC - How to Implement DI That Has Scope?

I'm writing an IoC container for my own learning/growth. Normally I would write something like the following: using(DisposableObject dispObj = new DisposableObject()) { UserRepository users = new UserRepository(dispObj); // Do stuff with user. } Would turn to: using(IDisposableObject dispObj = Container.Resolve<IDisposableOb...

Return same instance for multiple interfaces

I'm registering components with the following code: StandardKernel kernel = new StandardKernel(); string currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location) foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!Path.GetDirectoryName(assembly.Location).Equals(currentDirectory)) continue;...

NHibernate session management in NServiceBus with Autofac

Andreas Ohlund has an excellent article here on how to use Structuremap to wire the NHibernate session so that it enlists in the NSB transaction automatically. Does anyone know if it is possible to achieve the same with Autofac? ...

Automatically set property after component creation with Autofac

Here is the example code: public interface IService<TEntity> { IContext Context { get; set; } //unimportant methods bool Validate(TEntity entity); void Add(TEntity enttity); } public class UsersController : Controller { private IService<User> _service; public MyController(ISe...

Autofac not passing same instance to resolved arguments in constructor

I have the following setup public class CommonClass : ICommonClass { } public class SomeClass : ISomeClass { public SomeClass(ICommonClass common, IOtherClass otherClass) {} } public class OtherClass : IOtherClass { public OtherClass(ICommonClass common) {} } //Registration builder.RegisterType<CommonClass>().As<ICommonClass>()....