autofac

PostSharp AssemblyLoadException Autofac

狂风中的少年 提交于 2019-12-22 13:12:02
问题 I am setting up a new solution in which I want to use the latest Autofac (3.4) and PostSharp 3.1.42. After referencing the NuGet packages I get the following error and I can't figure out what is going on. I never selected Autofac 3.3.0 package. packages.config: <package id="Autofac" version="3.4.0" targetFramework="net451" /> <package id="Autofac.Extras.Multitenant" version="3.1.1" targetFramework="net451" /> <package id="Autofac.Mvc5" version="3.3.0" targetFramework="net451" /> <package id=

PostSharp AssemblyLoadException Autofac

不羁岁月 提交于 2019-12-22 13:11:48
问题 I am setting up a new solution in which I want to use the latest Autofac (3.4) and PostSharp 3.1.42. After referencing the NuGet packages I get the following error and I can't figure out what is going on. I never selected Autofac 3.3.0 package. packages.config: <package id="Autofac" version="3.4.0" targetFramework="net451" /> <package id="Autofac.Extras.Multitenant" version="3.1.1" targetFramework="net451" /> <package id="Autofac.Mvc5" version="3.3.0" targetFramework="net451" /> <package id=

Configuring lifetime scopes in autofac when used as ServiceStack's IoC

℡╲_俬逩灬. 提交于 2019-12-22 10:27:15
问题 I'm currently using AutoFac as the DI container for our ServiceStack web services app. I'm able to configure the wiring and everything, but after reading the section on Scopes, I'm at a loss at which scope would be best to use when registering my components. In our particular case, I think a PerHttpRequest scope would be OK since (please correct me if im wrong) I would want to dispose the dependencies as soon as the request ends. My question is, how do I set this up in the container? I can't

Property Injection with internal setter

巧了我就是萌 提交于 2019-12-22 10:16:21
问题 I have an existing application that I am modifying to use Autofac Property Injection. It seems regardless of which method I use to register my types with properties, the properties are always null unless they have public setters. With other IoC containers (e.g. Structuremap) it's possible to scope the setter internal and make it available using the InternalsVisibleTo attribute on the assembly. This would seem nice to restrict clients from modifying the assignment. Is this possible with

Dependency Injection in ASP.net Session_Start method

我的梦境 提交于 2019-12-22 09:25:54
问题 I am learning dependency injection and using autofac for the first time. I built the container as mentioned in several autofac examples (see below) and called from my application_start public class ContainerConfig { public static void RegisterContainer() { //Create a new ContainerBuilder var builder = new ContainerBuilder(); // Register all the controllers using the assembly object builder.RegisterControllers(Assembly.GetExecutingAssembly()); //Registering default convention -- IExample and

Autofac Losing Registrations on Web.Config Edit

给你一囗甜甜゛ 提交于 2019-12-22 09:14:29
问题 I have a layered web application that I built with ASP.NET MVC 4, WebAPI and some other components. I'm using the latest release of Autofac 2.6.2.859 as my DI container along with the MVC and WebAPI integrations. I have autofac modules setup in my different layers and I'm using the new RegisterAssemblyModules to scan the AppDomain assemblies for the various modules. On startup every works great. When I edit the web.config file and the application warms up, my registrations are lost. I get a

Autofac Binding at Runtime

感情迁移 提交于 2019-12-22 08:44:29
问题 I currently use Autofac to do simple constructor injection without any issues. However what I would like to know is how to resolve dependencies at runtime. The example below shows multiple ways in which we can export a document. With simple constructor injection the concrete implementation of IExport is resolved at runtime. However what need to do is to resolve IExport on a user selection from a dropdown list which will happen after the construction of my container. Is there any examples of

IoC is not initialized on Win7/XP

南楼画角 提交于 2019-12-22 08:29:06
问题 I'm facing a quite strange problem trying to run a WPF application on Win7/XP. The WPF application targets .NET 4.0 and it references Caliburn.Micro 1.5.2 and Autofac 3.1.0 . I'm going to start with a summary of the problem and then I'm going to give details about what I've got so far. OVERVIEW In my dev workstation I have Windows 8 and Visual Studio 2012. I'm using Caliburn and Autofac as described in this post (basically a simplified version of this). When I build and run the application in

Register string value for concrete name of parameter

为君一笑 提交于 2019-12-22 08:19:01
问题 I am using Autofac and I have several classes which ask for parameter of type string and name lang. Is there a way to register a string value to all parameters named "lang", so it resolves automatically? I do not want to edit any of the constructors, since it is not my code (I know accepting e.g. CultureInfo would make registration easy..) Something resulting in short syntax like builder.Register(lang => "en-US").As().Named("lang") would be ideal. Thank you. 回答1: A fairly simple way to solve

Avoiding Service Locator with AutoFac 2

血红的双手。 提交于 2019-12-22 07:44:20
问题 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) { _resolver = resolver; } public static T Resolve<T>() { return _resolver.Resolve<T>(); } } From answers to a previous question, I found a way to help reduce the need for using my