autofac

Resolving HttpRequestScoped services in ASMX with Autofac 2.1.12

The Description I had a legacy type that is HttpRequestScoped and a legacy web service consuming that service. To resolve services in legacy concerns, I have a global resolver. This was all working well in 1.4, and now that I'm using 2.1.12 I'm experiencing DependencyResolutionException. The Code In 2.1.12, my Global.asax.cs: builder.R...

Can't resolve NameValueCollection with Autofac

I am using Autofac 2.1.12 to handle my dependency injection, and am having trouble with one specific issue. I can't seem to resolve a NameValueCollection dependency. Consider the following code snippet: class Foo { public Foo(NameValueCollection collection) { } } static class Run { public static void Main() { var b...

Does/Will autofac's ASP.NET integration support PreInit or Init events?

I see from poking around in the 1.4.4 source that Autofac's ASP.NET integration (via Autofac.Integration.Web) peforms injection of properties on the Page as part of the HttpContext.PreRequestHandlerExecute event handling, but that the page's child controls don't get their properties injected until Page.PreLoad. What this means, though i...

Autofac Wcf Integration Security Problem

I've created a Wcf Service to back a Ajax page (.Net 3.5). It's hosted in IIS 6.1 Integrated Pipeline. (The rest of Autofac is setup correctly for Web Forms integration). Everything works fine and dandy with the normal Wcf pipeline. However when I plug in the Autofac Wcf Integration (as per the Autofac wiki) I get this delightful exc...

RenderAction not finding action method in current controller in current area

I'm creating an ASP.NET MVC 2 (RTM) project that uses areas. The Index action of the Home controller of one area needs to use RenderAction to generate a sub-section of the page. The action called is also defined in the same Home controller. So the call should just be: <% Html.RenderAction("List") %> However, I get an exception: A pub...

Resolve dependency with autofac based on constructor parameter attribute

I'm using Autofac. I want to inject a different implementation of a dependency based on an attribute I apply to the constructor parameter. For example: class CustomerRepository { public CustomerRepository([CustomerDB] IObjectContainer db) { ... } } class FooRepository { public FooRepository([FooDB] IObjectContainer db) { ... } ...

Can't get autofac to resolve type that, apparently, is registered

Hi all, Has stated on the title, I'm trying to get autofac to resolve a type, that, as seen on the image bellow, seems registered. Any thoughts on why the exception? Thanks UPDATE 1 Hi, I've moved to the latest build of the autofac. I'm registering the DemoService this way: public class DependenciesModule : Autofac.Module { prot...

Autofac or Ninject? - which should I go for?

I'm hitting paralysis by analysis I think... Which should I go for for my first IOC container: Autofac or Ninject? (Just want an open source, nice and simple, IOC container) ...

Autofac in Asp.net mvc 2

I want/need to compile autofac with asp.net mvc 2 website. I want to step thru the source to see how it works. But here is my problem. The binaries for mvc dll is apparently bound for asp.net mvc 1. I am having trouble working out what the settings for the project file need to be for .Net 3.5 and asp.net mvc 2. one is the NET35 directiv...

Implementing auditing using Autofac if it support method interception?

I'm planning to use Autofac IoC for my project where I must implement auditing (Who, What is doing in application). I was already read a lot of articles on this subject (auditing). My intention was to use method interception to implement this functionality. I know that Unity support this, but I was wondering if I can use Autofac for thi...

Autofac: Reference from a SingleInstance'd type to a HttpRequestScoped

I've got an application where a shared object needs a reference to a per-request object. Shared: Engine | Per Req: IExtensions() | Request If i try to inject the IExtensions directly into the constructor of Engine, even as Lazy(Of IExtension), I get a "No scope matching [Request] is ...

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 have everything working perfectly apart from the selective part. I could be wrong, but I ...

Resolution Problem with HttpRequestScoped in Autofac

I'm trying to resolve the AccountController in my application, but it seems that I have a lifetime scoping issue. builder.Register(c => new MyDataContext(connectionString)).As<IDatabase>().HttpRequestScoped(); builder.Register(c => new UnitOfWork(c.Resolve<IDatabase>())).As<IUnitOfWork>().HttpRequestScoped(); builder.Register(c => new...

Reinject dependencies of a freshly deserialized object

If a program has literally just deserialized an object (doesn't really matter how, but just say BinaryFormatter was used). What is a good design to use for re-injecting the dependencies of this object? Is there a common pattern for this? I suppose I would need to wrap the Deserialize() method up to act as a factory inside the containe...

property inject in Autofac

I am compiling: PropertyInject wiki page why this line: builder.RegisterType().InjectProperties(); doesn't compile? how to do property inject in autofac? I am using vs2010, autofac 2.1.13.813. thanks. EDIT: after investigation, PropertyInjection should be like this in new version of AutoFac: builder.RegisterType().PropertiesAutow...

Different controllers with the same name in two different areas results in a routing conflict

I have two areas: ControlPanel and Patients. Both have a controller called ProblemsController that are similar in name only. The desired results would be routes that yield /controlpanel/problems => MyApp.Areas.ControlPanel.Controllers.ProblemsController and /patients/problems => MyApp.Areas.Patients.Controllers.ProblemsController. Ea...

Issue with Autofac 2 and MVC2 using HttpRequestScoped

I'm running into an issue with Autofac2 and MVC2. The problem is that I am trying to resolve a series of dependencies where the root dependency is HttpRequestScoped. When I try to resolve my UnitOfWork (which is Disposable), Autofac fails because the internal disposer is trying to add the UnitOfWork object to an internal disposal list ...

Resolve instance - Autofac

I'm trying to figure out how to resolve a instance somewhere in the code. At the application startup I registered a type static void Main() { var builder = new ContainerBuilder(); builder.RegisterType<Foo>().As<IFoo>(); } Now, how can I resolve an instance somewhere in the code ? In structure mam there is a static object...

Avoiding Service Locator with AutoFac 2

I'm building an application which uses AutoFac 2 for DI. I've been reading that using a static IoCHelper (Service Locator) should be avoided. IoCHelper.cs public static class IoCHelper { private static AutofacDependencyResolver _resolver; public static void InitializeWith(AutofacDependencyResolver resolver) { _res...

constructor injection using Autofac 2 and Named Registration

I am currently attempting to remove a number of .Resolve(s) in our code. I was moving along fine until I ran into a named registration and I have not been able to get Autofac resolve using the name. What am I missing to get the named registration injected into the constructor. Registration builder.RegisterType<CentralDataSessionFacto...