Questions tagged [autofac-configuration]

88 questions
21
votes
6 answers

Autofac - Make sure that the controller has a parameterless public constructor

I know it's been asked and answered before - the reason I'm asking is because (I think) I tried all suggested solutions to this problem but still can't resolve it. I have an ASP.NET Web API 2.0 project. I have Autofac, Autofac.Mvc5 and…
developer82
  • 13,237
  • 21
  • 88
  • 153
20
votes
1 answer

Inheritance security rules violated while overriding member: 'Autofac.Integration.WebApi.AutofacWebApiDependencyResolver.BeginScope()'

I am trying to build an asp.net web api 2.0 application using VS 2012 and asp net web tools for vs 2012 on .Net 4.5.2 framework; when i try to run the application, Inheritance security rules violated while overriding member:…
15
votes
1 answer

Autofac IComponentContext vs ILifetimeScope

I was passing the IContainer in a service so I read that it is not good to pass this around but instead use it only to the root of the app and pass either IComponentContext or ILifetimeScope . So I am trying to understand which shall I use…
pantonis
  • 5,601
  • 12
  • 58
  • 115
7
votes
1 answer

Configuring Autofac with ASP.NET MVC 5

I am trying to implement Dependency Injection with Autofac in an ASP.NET MVC5 Project. But I am getting the following error every time: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type…
TanvirArjel
  • 30,049
  • 14
  • 78
  • 114
6
votes
1 answer

Configure AutoFac in ASP.NET Core 3.0 Preview 5 or higher

Following the AutoFac documentation, I was able to use AutoFac in ASP.NET Core 3.0 Preview 3. ASP.NET Core 3.0 Preview 4 and ASP.NET Core 3.0 Preview 5 introduced breaking changes and AutoFac no longer works. My controller methods return runtime…
6
votes
2 answers

Autofac ignores registration conflicts

I have the following test [TestFixture] public class Test { public interface IMy { } class MyClass : IMy { } class MyClass2 : IMy { } [Test] public static void Go() { var builder = new ContainerBuilder(); …
Alex Ilyin
  • 1,294
  • 1
  • 12
  • 22
3
votes
3 answers

Inject instance of ILogger in my component class Azure Functions using Autofac

I am writing a simple Azure function. I have installed the AzureFunctions.Autofac nuget package, and would like to use this as my DI library. I have set up the following AutofacConfig class to register my types: public class AutofacConfig { …
monstertjie_za
  • 7,277
  • 8
  • 42
  • 73
3
votes
0 answers

ArgumentNullException when using new XML configuration in Autofac / Nancy app

Autofac since version 4 uses the new Microsoft Configuration. According to the documentation the following XML-file should be valid.
Sardaukar
  • 29,034
  • 5
  • 26
  • 32
3
votes
3 answers

In Autofac, how do you register the Owned relationship when A is a single instance and B is registered using InstancePerRequest?

I am using Autofac version 3.5.2. I want to register a singleton class A that needs B until some point in the future. How do you do this if B is registered using InstancePerRequest? Using Owned directly does not work because the per request…
Landon
  • 76
  • 6
2
votes
2 answers

Reduce increasing Constructor service parameters

I'm still new to using Autofac and I'm bothered by the constructor injection method that I'm using. Here's the scenario: I currently have two classes which inherits the IForms interface. Each of the classes has its own interface as well public…
Musikero31
  • 3,115
  • 6
  • 39
  • 60
2
votes
0 answers

Autofac RegisterAssemblyModules throws Autofac.Core.DependencyResolutionException

I have a WebAPI 2 that uses Autofac. Below works, but RegisterAssemblyModules throws DependencyResolutionException builder.RegisterModule(); //works builder.RegisterModule(); …
2
votes
2 answers

Autofac inject properties on ApiController in combination with RegisterApiControllers

I want to inject Modules and Data properties from an autofac.json file into my ApiController with name DataController I read this page: http://docs.autofac.org/en/latest/configuration/xml.html but my properties keep being NULL, so I must be doing…
321X
  • 3,153
  • 2
  • 30
  • 42
2
votes
0 answers

Autofac not resolving constructor parameter for WebAPI2 controllers

I'm trying to use Autofac for DI container for an Asp.Net MVCApplication with WebApi2 and OWIN. My global.asax.cs has nothing in the Application_Start(). My startup.cs has the following Configuration: public void Configuration(IAppBuilder app) { …
PMontgomery
  • 424
  • 4
  • 17
2
votes
1 answer

Where is AddJsonFile extenstion method for Autofac 4.0

In the Autofac documentation, they provide a brief example of injecting a component via a service... However, I'm unable to locate the extension method AddJsonFile .. The provided snippet is: var config = new…
codeputer
  • 1,987
  • 3
  • 19
  • 45
2
votes
1 answer

Register autofac component with optional parameters object

I would like to register a component with an optional parameter in the constructor. I saw passing optional parameter to autofac that looks good but not sure how I can implement this with xml configuration. Let's say this is my code: public…
Daniel Rapaport
  • 375
  • 2
  • 18
1
2 3 4 5 6