autofac

Autofac Dependency Injection works in Debug but crashes in Release

a 夏天 提交于 2019-12-10 14:56:09
问题 What would cause my DI to crash in Release mode when it's fine in Debug mode? This is a Xamarin.Forms app, and is being run on Android. 07-23 20:56:53.002 I/MonoDroid(15451): UNHANDLED EXCEPTION: Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> Object reference not set to an instance of an object (See inner exception for details.) ---> System.NullReferenceException: Object reference not set to an

Can components be temporarily registered in an Autofac container?

不羁岁月 提交于 2019-12-10 14:27:33
问题 I'm building a plugin for a 3rd party application and my plugin uses Autofac to wire up various components. The container is built at application startup, but the host application invokes my commands at a later time. When a command is invoked, the host application provides a few instances of types that it defines and that my components will need to use. I'd like to register these instances in the container so that it can take care of wiring up the components that depend on these instances. I

Loading all referenced assemblies .NET even if not used explicitly in code

断了今生、忘了曾经 提交于 2019-12-10 13:45:47
问题 We have a windows service which is using Autofac, when we try to load the referenced assemblies not all are listed as some contain objects we aren't using anywhere in the application but interface implementations are in there we need to be included. The following method loads the assemblies: private IEnumerable<Assembly> GetReferencedAssemblies(Assembly assembly) { var assemblyNames = assembly.GetReferencedAssemblies(); List<Assembly> assemblies = new List<Assembly>(); assemblies.Add(assembly

What is InstancePerLifetimeScope in Autofac?

我的未来我决定 提交于 2019-12-10 13:38:03
问题 Can someone please explain in plain English what the lines of code where I put the question marks do? Or maybe point me to an article that puts light on this. This code is for registering dependencies in an autofac container var builder = new Autofac.ContainerBuilder(); builder.Register<NHibernateInstance>(c => new NHibernateInstance(ConnString, false)) .InstancePerDependency();//????? builder.Register(c => c.Resolve<NHibernateInstance>() .GetFactory().OpenSession()) .As<ISession>()

Autofac is not filling action filter property

柔情痞子 提交于 2019-12-10 13:20:18
问题 I have an action filter in an ASP.NET MVC 3 app that needs some dependencies injected into it. I am using Autofac.Mvc3 as the dependency injector. According to the autofac wiki I just have to register the types that I want to inject, call RegisterFilterProvider , and put a public property on my action filter, and then autofac will fill the property with the right object during filter instantiation. Here is a part of my action filter: Public Class LogActionAttribute Inherits

Per-Request DependencyResolver in Web API

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 12:54:58
问题 In MVC, a ModelValidatorProvider is instantiated and called to validate a model on each request. This means that in a DI environment, it can take dependencies on objects scoped within a single request, such as a Unit of Work or Database context. In Web API, this appears to have been significantly changed. Instead of being instantiated per-request, the ModelValidatorProvider appears to be long-lived and instantiated within the application startup. The WebAPI then caches the results from the

Resolving Hangfire dependencies/HttpContext in .NET Core Startup

允我心安 提交于 2019-12-10 12:45:54
问题 I've installed and configured Hangfire in my .NET Core web application's Startup class as follows (with a lot of the non-Hangfire code removed): public class Startup { public void Configuration(IAppBuilder app) { app.UseHangfireServer(); //app.UseHangfireDashboard(); //RecurringJob.AddOrUpdate(() => DailyJob(), Cron.Daily); } public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddOptions(); services.Configure<AppSettings>(Configuration); services.AddSingleton

Areas not displaying in MVC 4 using MvcExtensions

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:20:18
问题 I am using ASP.NET MVC 4 RC and the latest version of MvcExtensions and MvcExtensions.Autofac . I don't know if MVC 4 works differently to MVC 3, but my areas aren't displaying at all when using it with MvcExtensions. The code below is how I used it in my MVC 3 application. I have just copied and pasted it into my MVC 4 app. If I use the default Global.asax.cs file that came with the MVC 4 application then my areas display properly. Must this be done differently? I replaced the Global.asax.cs

Autofac - SignalR with OWIN. getting reference to the ContainerBuilder

流过昼夜 提交于 2019-12-10 11:49:28
问题 I have an existing MVC 4 application that uses Autofac and I have other assemblies that have autofac Modules in. Without SignalR/autofac integration, my application works perfectly as far as IOC is concerned. I have added in SignalR hubs which I am trying to inject dependencies into via the constructor. I have followed the documentation and implemented the code example from. http://autofac.readthedocs.org/en/latest/integration/signalr.html Which results in this following class: public class

Register a Presenter with a View

北慕城南 提交于 2019-12-10 11:27:03
问题 If I have a presenter like this - public class LandingPresenter : ILandingPresenter { private ILandingView _view { get; set; } private IProductService _productService { get; set; } public LandingPresenter(ILandingView view, IProductService) { .... } } How do I register this Presenter with Autofac considering the dependent view will not be registered (but IProductService will) builder.RegisterType<LandingPresenter>().As<ILandingPresenter>(); ???? 回答1: Why not register the views in the