autofac

how to resolve a dependency between two tightly coupled namespace(in different assembly)?

旧时模样 提交于 2019-12-11 20:18:52
问题 suppose i have an interface called ITestService with it's paired implementation, lets call it DefaultTestService in Assembly "A". I register DefaultTestService class as ITestService service in Autofac container. On the other hand assembly "A" has a reference to assembly "B".now I want to resolve DefaultTestService through it's corresponding interface (ITestService) in assembly "B", for doing this first I have to add reference to assembly "A" so that I can access and pass ITestService to

How do I register a delegate or function with Autofac when the function belongs to a class that must be resolved?

浪尽此生 提交于 2019-12-11 19:07:39
问题 I'm using Autofac. I want to inject a delegate into a class: public delegate ValidationResult ValidateAddressFunction(Address address); public class OrderSubmitHandler { private readonly ValidateAddressFunction _validateAddress; public OrderSubmitHandler(ValidateAddressFunction validateAddress) { _validateAddress = validateAddress; } public void SubmitOrder(Order order) { var addressValidation = _validateAddress(order.ShippingAddress); if(!addressValidation.IsValid) throw new Exception("Your

Azure Webjob - Per Request Lifetime?

China☆狼群 提交于 2019-12-11 17:30:18
问题 I have a console app that I'm using for an azure webjob. I need to have a unique nhibernate session per azure webjob request . I'm using autofact to manage DI. How can I get Per Request Lifetime instancing in azure webjobs? Inherently a console app doesn't have this. Do I need to change project types? I've seen several answers on how to do something similar here and here. But they basically boil down to passing in a container as a parameter to functions. That's not really instance per request

ConfigurationModule passed into Module and context - DotNet Core

两盒软妹~` 提交于 2019-12-11 16:31:54
问题 So I'm trying to use Autofac DI to pass my configuration json file through the stack. My Main function is as follows: static void Main(string[] args) { Console.WriteLine("Starting..."); // Add the configuration to the ConfigurationBuilder. var config = new ConfigurationBuilder(); config.AddJsonFile("appsettings.json"); var containerBuilder = new ContainerBuilder(); // Register the ConfigurationModule with Autofac. var configurationModule = new ConfigurationModule(config.Build());

Injecting ISecureDataFormat in Web API 2 AccountController using Autofac

房东的猫 提交于 2019-12-11 16:28:45
问题 I am using ASP.NET Identity 2.2 in a Web API 2 project but I am unsure how to wire up the ISecureDataFormat<AuthenticationTicket> dependency of the AccountController using Autofac . I tried this: builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>() .As<TicketDataFo‌​rmat>(); and getting error: The type 'Microsoft.Owin.Security.ISecureDataFormat`1[Microsoft.Owin.Security.Authenticat‌​ionTicket]' is not assignable to service 'Microsoft.Owin.Security.DataHandler.TicketDataFormat' None

Autofac - How to resolve instances registered using JSON Configuration

纵饮孤独 提交于 2019-12-11 16:02:46
问题 Our requirement is to have different Logger instances for different user defined threads. { "defaultAssembly": "Framework", "components": [ { "type": "SynapseMiddleware.Core.Framework.LoggerServicePerContext, Framework", "services": [ { "type": "SynapseMiddleware.Core.Framework.ILoggerServicePerContext, Framework" } ], "parameters": { "loggerConfig": "18105" } }, { "type": "SynapseMiddleware.Core.Framework.LoggerServicePerContext, Framework", "services": [ { "type": "SynapseMiddleware.Core

Binding autofac with webapi using generic repository

一世执手 提交于 2019-12-11 13:54:10
问题 I am trying to use autofac with a repository and I am trying to add a little generics to try reducing the amount of duplicate code I am writing.However I am going round in circles trying to get autofac to work for me So I created a domainservice and interface that handles our the standard crud operations public class DomainService<T>:IDomainService<T> { protected readonly IDomainService<T> Repository; public DomainService(IDomainService<T> repository) { Repository = repository; } public

Can I make a keyed service for AutoFac based on the type of the Open Generic

流过昼夜 提交于 2019-12-11 13:52:12
问题 I would like to make a keyedService based on the T for my Open Generic ICommandHandler. I would like to register a ConsultatCommandHanlder keyed service when the ICommandHandler has a T that inherits from ConsultantCommand Any idea how to do it? Or if it is even possible? I am new to AutoFac and am struggling. I am presently registering CommandHandler like this: //Register All Command Handlers builder.RegisterAssemblyTypes(assemblies) .As( t => t.GetInterfaces() .Where(a => a.IsClosedTypeOf

NServiceBus IoC Serialization Exception

家住魔仙堡 提交于 2019-12-11 13:51:19
问题 I am using a "custom" object builder (Autofac) so I can re-use the registration of many types that I have done in a common assembly. When I run the service, hosted within NServiceBus.Host.exe, I get the following error: SerializationException was unhandled: Type 'Autofac.Core.Registration.ComponentNotRegisteredException' in assembly 'Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' is not marked as serializable. This seems odd to me because NServiceBus uses Autofac

InstancePerApiControllerType not working

Deadly 提交于 2019-12-11 13:49:04
问题 I am attempting to configure a web service with Autofac so that I can map a different connection context for each controller: // database connections container.Register(c => new DocumentControllerActivator()).As<IHttpControllerActivator>().InstancePerApiControllerType(typeof(DocumentController)); container.Register(c => new WorkflowControllerActivator()).As<IHttpControllerActivator>().InstancePerApiControllerType(typeof(WorkflowController)); and: public class WorkflowControllerActivator :