autofac

Autofac pick nested implementation based on parent dependency

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:13:45
问题 Given the example dependency tree below I would like to select the bottom level Config instance based on the top level dependency being resolved from the container e.g. TopLevelMessageConsumer would resolve the same IMessageService & IMessageQueue implementations as TopLevelMessageDispatcher but each would have their own Config instance. - TopLevelMessageConsumer - IMessageService - IMessageQueue - Config - TopLevelMessageDispatcher - IMessageService - IMessageQueue - Config I know this is

Intercepting a WCF Service with Autofac

别等时光非礼了梦想. 提交于 2019-12-13 04:05:45
问题 I am attempting to intercept methods on a WCF service server side with the following registration: containerBuilder.RegisterType<Service>().As<IServiceContract>().InstancePerLifetimeScope() .EnableInterfaceInterceptors().InterceptedBy(typeof(MethodInterceptor)); however, when I do the service endpoint disappears. The WCF service is hosted inside a Windows Service. Any ideas? The exception I receive is as follows: System.ServiceModel.EndpointNotFoundException: There was no endpoint listening

Autofac scope configuration for multi-project solution

血红的双手。 提交于 2019-12-13 03:46:10
问题 I have an ASP.NET web application which until now has been using an Autofac configuration class which has specified an InstancePerRequest() for services in the application. Since then, I have created a new console application in the same solution which will be responsible for running automated job processes. Since I can't use the InstancePerRequest configuration for my console application, then I need to make a change to my configuration. Ideally, I don't want to copy and paste all the

Autofac: Reference from a SingleInstance'd type to a HttpRequestScoped

纵然是瞬间 提交于 2019-12-13 02:38:14
问题 I've got an application where a shared object needs a reference to a per-request object. Shared: Engine | Per Req: IExtensions() | Request If i try to inject the IExtensions directly into the constructor of Engine , even as Lazy(Of IExtension) , I get a "No scope matching [Request] is visible from the scope in which the instance was requested." exception when it tries to instantiate each IExtension . How can I create a HttpRequestScoped instance and then inject it into a shared instance?

Using Autofac to inject services defined in Web API HttpConfiguration

懵懂的女人 提交于 2019-12-13 02:26:23
问题 When using Autofac with ASP.NET Web API, is there any way to resolve dependencies using the services registered in HttpConfiguration or even the HttpConfiguration itself. For instance, I would like to have a controller with a constructor that receives the config's registered ITraceWriter or the HttpConfiguration itself. I know that the configuration is available in the action methods, but I would like to use it in the constructor. Thanks. edit 1 I've found a way to make the current

IAutofacActionFilter injecting a logger

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:04:41
问题 I'm using NLog with this module: public class LoggingModule : Autofac.Module { protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) { registration.Preparing += OnComponentPreparing; registration.Activated += (sender, e) => InjectLoggerProperties(e.Instance); } private static void OnComponentPreparing(object sender, PreparingEventArgs e) { var t = e.Component.Activator.LimitType; e.Parameters = e.Parameters.Union( new[

Autofac registration and disposal issues

♀尐吖头ヾ 提交于 2019-12-13 01:14:57
问题 I'm using entity framework 6 and Autofac in my web application. I inject unit of work with DbContext inside, both externally owned so I can dispose them myself. DbContext registered PerLifetimeScope, Unit of work is a factory, therefore registered as per dependency. When Executing the first http Get action everthing works fine and I see the unit of work with the context are disposed after the response is coming from the db which is great. My issue is that whenever I execute a second request,

Unable to resolve AutoFac Keyed service with KeyFilterAttribute not working

自闭症网瘾萝莉.ら 提交于 2019-12-13 00:23:58
问题 I have a generic UnitOfWork pattern implementation and these UnitOfWork objects are dependencies to my service classes. Below snippets should help the reader understand my code setup: IUnitOfWork interface public interface IUnitOfWork<out TContext> where TContext : IDbContext UnitOfWork class public sealed class UnitOfWork<TContext> : IDisposable, IUnitOfWork<IDbContext> where TContext : IDbContext { private static readonly ILog Log = LogManager.GetLogger(typeof(UnitOfWork<TContext>));

Autofac resolve in deep layer

流过昼夜 提交于 2019-12-12 20:34:23
问题 I'm having hard time integrating autofac in my applcation.. My application integrates with other applications, when a connection to another application is made its being maintained by a fitting "Protocol" object // This class is inherited by a few other classes public abstract class Protocol I have a layer that is run by it's own thread and handles connection requests. For each kind of request a different kind of protocol is created (a different protocol object) // For example lets say every

Uses of PreserveExistingDefaults?

跟風遠走 提交于 2019-12-12 16:08:19
问题 Why and when should we use PreserveExistingDefaults during autofac registration? I have read it's uses form Autoface docs: http://docs.autofac.org/en/latest/register/registration.html But my question is, when is the case we will register multiple implementation with single interface. Can anybody give some example from real time. 回答1: It can be use when you want to register a new implementation without changing the default one. When you register multiple registration for a single interface,