autofac-module

Read modules from web.config in autofac to change container configuration according to solution configurations

断了今生、忘了曾经 提交于 2020-01-06 06:51:35
问题 I have created some Autofac modules... Now I want to register some of them in my container using web.config... In my web.config I have written: <autofac defaultAssembly="Autofac.Example"> <modules> <module type="DebugModuleTest1"></module> <module type="DebugModuleTest2"></module> </modules> </autofac> Now I have to build my container. But the autofac documentation is not clear to me. I do not understand what I have to do to read my modules and build the container. public class

Register callback in Autofac and build container again in the callback

做~自己de王妃 提交于 2019-12-24 19:28:39
问题 I have a dotnet core application. My Startup.cs registers types/implementations in Autofac. One of my registrations needs previous access to a service. var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterSettingsReaders(); // this makes available a ISettingsReader<string> that I can use to read my appsettings.json containerBuilder.RegisterMyInfrastructureService(options => { options.Username = "foo" //this should come from appsettings }); containerBuilder.Populate(services

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[

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());

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

None of the constructors found can be invoked with the available services and parameters Autofac

丶灬走出姿态 提交于 2019-12-11 12:15:08
问题 I have read and coding follow example: http://timschreiber.com/2015/01/14/persistence-ignorant-asp-net-identity-with-patterns-part-1/ But that example used Unity for DI, but i'm used Autofac for ID, when i try run my project i have the following error: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'App.Front.Controllers.HomeController' can be invoked with the available services and parameters: Cannot resolve parameter 'Microsoft

Net Core: access to appsettings.json values from Autofac Module

情到浓时终转凉″ 提交于 2019-12-06 02:32:48
问题 AspNet core app 1) Autofac module like that public class AutofacModule : Module { protected override void Load(ContainerBuilder builder) { //Register my components. Need to access to appsettings.json values from here } } 2) Module from step№1 registered into Startup.cs public void ConfigureContainer(ContainerBuilder builder) { builder.RegisterModule(new AutofacModule()); } How to access to appsettings.json values from AutofacModule ? I need that for create my objects inside AutofacModule and