autofac

Adding Autofac to WPF MVVM application

我们两清 提交于 2019-12-05 02:46:14
I can't seem to find an solution to this problem. I've seen several questions about this, but none really give me a solution. I am totally new to Autofac and haven't really done much WPF + MVVM, but know the basics. I have a WPF application (using ModernUI for WPF) which I'm trying to add Autofac to, and I am having a hard time figuring out how to resolve my services within all the views, since they have no access to my container. I have a main view, which is my entry point, where I set up my container: public partial class MainWindow : ModernWindow { IContainer AppContainer; public MainWindow

Autofac 3 and Automapper

断了今生、忘了曾经 提交于 2019-12-05 02:03:37
问题 Does anyone know of a comprehensive guide to setting up Automapper with Autofac. I'm new to both but I have played around with the static Mapper class however I want to be able to mock and inject IMappingEngine and create a configuration that sets up all my mappings. All the guides I have looked at so far don't really explain what is going on and I can't quite work it out. Also I am using Autofac 3.0 which seems to have some differences in the ContainerBuilder methods which doesn't help (the

Xamarin, Autofac, NavigationService and BeginLifetimeScope

两盒软妹~` 提交于 2019-12-05 00:52:56
问题 A beginner question on lifetimescopes with autofac and when to use them, in a xamarin app. As mentioned in this article (https://nblumhardt.com/2011/01/an-autofac-lifetime-primer/) which is referred to by the autofac documentation (http://docs.autofac.org/en/latest/lifetime/) they hammer a lot on not resolving from the root container but using seperate lifetimescopes and thinking in terms of units of work because autofac hold referenences to disposable objects even if they are not used

Is it possible to inject a list of resolved objects into a constructor using Autofac?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 00:38:22
I'm new to Autofac (3) and am using it to find a number of classes in several assemblies that implement IRecognizer. So I have: builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()).As<IRecognizer>(); which is fine. But I'd like to inject references to the found components into a constructor - sort of: public Detector(List<IRecognizer> recognizers) { this.Recognizers = recognizers; } Is there any way to do this? nemesv Autofac supports the IEnumerable<T> as a relationship type: For example, when Autofac is injecting a constructor parameter of type IEnumerable<ITask> it will

Autofac with MVC4: controller does not have a default constructor

懵懂的女人 提交于 2019-12-04 23:19:06
I've been working with Autofac in MVC3 and love it. Now I am trying to implement it with MVC4. I installed the pre-release versions of Autofac MVC4 and Autofac WebApi through the Package Manager Console (Install-Package Autofac.Mvc4 -Pre and Install-Package Autofac.WebApi -Pre) I adjusted my IoC container as following: private static void SetAutofacContainer() { var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<UnitOfWork>().As<IUnitOfWork>()

Resolving AutoFac dependencies inside Module class

孤街浪徒 提交于 2019-12-04 23:07:32
I'm new to AutoFac and am currently using custom modules inside my app config to boot up some core F# systems. The code I'm using is var builder = new ContainerBuilder(); builder.RegisterType<DefaultLogger>().As<IDefaultLogger>(); builder.RegisterModule(new ConfigurationSettingsReader("autofac")); builder.Build(); And inside my app config I have the appropriate logic to start up the relevant systems. I would like to have access to the DefaultLogger inside my Modules. Metadata for the Module base class has the following options available to me: protected virtual void

Autofac Lifetime Scope Decorator

自作多情 提交于 2019-12-04 21:55:52
I am implementing a command handler pattern using Autofac and am using it's decorator facility handle cross cutting concerns such as logging, authentication etc. I also have dependencies that I only want scoped to the lifetime of the request / response pipeline. I have an example implementation below: public class Program { public static void Main() { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(HandlerModule).Assembly); builder.RegisterType<LifetimeScopeTester>().AsSelf() .InstancePerMatchingLifetimeScope("pipline"); var container = builder.Build(); using(var

Using log4net with WebApi - Keeping same correlation id throughout instance

雨燕双飞 提交于 2019-12-04 20:07:50
问题 I have a LoggingHandler class that I'm using as a message handler to log (using log4net) request and responses to my WebApi public class LoggingMessageHandler : DelegatingHandler { public ILogManager LogManager { get; set; } protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { var controllerType = GlobalConfiguration.Configuration.Services .GetHttpControllerSelector() .SelectController(request)

Custom ControllerFactory with autofac

瘦欲@ 提交于 2019-12-04 19:41:02
First of all i am a newbie in asp mvc so please be patient. Currently I want to create project where autofac will be IoC container i will reqister custom controller factory. In custom controller factory I want to set implementation Data Repository via constructor of controller. I thought it should be done in that way: ContainerBuilder builder = new ContainerBuilder(); builder.RegisterControllers(asm).InstancePerHttpRequest(); builder.Register(s => new ControllerFactory()).As<IControllerFactory>(); IContainer container = builder.Build(); DependencyResolver.SetResolver(new

MVC WebApi not using AutofacWebApiDependencyResolver

假如想象 提交于 2019-12-04 19:32:58
问题 I have a mixed MVC 4 app, where some controllers are regular implementations of Controller and some controllers are implementations of ApiController . I'm also using Autofac for DI, but it appears that the WebApi controller "activator" machinery (for lack for a more specific term) is not using the Autofac resolver ( AutofacWebApiDependencyResolver ), which leads to an exception being thrown when I make a request against one of my api controllers. Here's the error: <Error> <Message>An error