autofac

What is the disadvantage of manually registering Log4Net Logger instance to ILog in Autofac?

落花浮王杯 提交于 2019-12-11 01:28:56
问题 Autofac has log4net Integration Module called LoggingModule . However, I register Logger to ILog manually without using LoggingModule , and it seems working fine. ILog log = LogManager.GetLogger("Logger"); builder.RegisterInstance(log).As<ILog>().SingleInstance(); My question is - what is the disadvantage/side effect of using above approach instead of using LoggingModule . web.config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net" type="log4net

How to using container.Resolve in Module?

和自甴很熟 提交于 2019-12-11 01:19:47
问题 I am beginner with Autofac. Does anyone know How to using container.Resolve in Module? public class MyClass { public bool Test(Type type) { if( type.Name.Begin("My") ) return true; return false; } } public class MyModule1 : Autofac.Module { protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) { var type = registration.Activator.LimitType; MyClass my = container.Resolve<MyClass>(); //How to do it in Module? my.Test

Autofac - Exception: An item with the same key has already been added

北城余情 提交于 2019-12-11 00:47:52
问题 I've just switched over to Autofac and it seems to be working well. However I've received one disconcerting error message whilst debugging the application. However I've since not been able to replicate it. I think this has something to do with a multithreading race condition. Autofac.Core.DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> An item with the same key has already been added. (See inner exception for

Autofac, Owin and memory leaks. Is autofac leaking with owin?

梦想的初衷 提交于 2019-12-10 23:39:38
问题 Recently I realized there is a leak in my Web API application based on Owin and Autofac. The leak is not permanent but memory kept longer than per request. Here's the deal: 1-) By default Web API uses buffered responses and the runtime keeps OverlappedData structure up to 40 instances as an object pool even after the response is returned. (For performance reasons I guess) 2-) Each OverlappedData structure keeps the OwinContext alive (only 40 at a time probably for pooling) 3-) Because

Can I create an implicit Lifetime scope within a factory?

不打扰是莪最后的温柔 提交于 2019-12-10 21:07:16
问题 Does Autofac support implicit lifetime scopes for the use of a factory? For example, I would like to be able to do the following public class Session : IDisposable { public Session(A a, B b, C c) { ... } } ... using (var session = _sessionFactory()) { ... } and then upon each call to the _sessionFactory have Autofac automatically create a nested lifetime scope? 回答1: Yes. Let the factory return Owned<Session> . Owned instances indicates that the calling code is responsible for disposing the

Autofac and memory leak with BeginLifetimeScope / DbContext has been disposed / C# asp.net

丶灬走出姿态 提交于 2019-12-10 21:04:35
问题 I am using NServiceBus Scheduler that's why I'm forced to use BeginLifetimeScope to avoid memory leak. Method: public void Start() { using (var scope = _lifetimeScope.BeginLifetimeScope()) { var jobs = scope.Resolve<IEnumerable<IJob>>(); foreach (var job in jobs) { _schedule.Every(job.GetTimeInterval(), () => { job.Run(); }); } } } And Autofac Configuration for context: private static void RegisterContext(ContainerBuilder builder) { builder.Register(c => new MyContext(GetConnectionString()))

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'

倾然丶 夕夏残阳落幕 提交于 2019-12-10 19:18:54
问题 I get the following error message: System.InvalidOperationException: An error occurred when trying to create a controller of type 'App.Web.Controllers.ContractWizardController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'App.Web.Controllers.ContractWizardController' can be invoked with the available services and

Register HttpContext.User with Autofac

给你一囗甜甜゛ 提交于 2019-12-10 19:02:27
问题 I would like to do the following in Autofac, but not sure how? This is how you do it in StructureMap ForRequestedType<IPrincipal>() .CacheBy(InstanceScope.Hybrid) .TheDefault.Is.ConstructedBy(ctx => HttpContext.Current.User); 回答1: For ASP.NET MVC 1 and 2: builder.Register(c => HttpContext.Current.User).HttpRequestScoped(); For ASP.NET MVC 3: builder.Register(c => HttpContext.Current.User).InstancePerHttpRequest(); For Autofac ASP.NET MVC3 integration you may take a look at the documentation

Whats the status of Prism integration in Autofac?

北战南征 提交于 2019-12-10 18:47:22
问题 Integration into Prism was talked about in the 2.1.x time frame, we are @ 2.4.x, Prism 4 is out now and the RIStockTrader Example in /contrib is just a default XAML project. Should it work? If so, anyone have a simple example of a Silverlight Shell + Bootstrapper + 1 Module they could point me to? 回答1: An updated Prism integration is currently in progress. I'm not sure what the status is exactly, but you can get the code and potentially contact the author here. You can also pass on feedback

Property Injection fails with Autofac

给你一囗甜甜゛ 提交于 2019-12-10 18:18:03
问题 I am using Autofac with MVC / Owin and WebApi. Following Autofac documentation I am using the setup: public static void Run(IAppBuilder application) { ContainerBuilder builder = new ContainerBuilder(); HttpConfiguration configuration = GlobalConfiguration.Configuration; builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterModelBinders(typeof(MvcApplication).Assembly); builder.RegisterModelBinderProvider(); builder.RegisterModule<AutofacWebTypesModule>(); builder