autofac

Inject a dependency in a SeriLog enricher with autofac

£可爱£侵袭症+ 提交于 2021-02-20 19:05:38
问题 I want to create a Serilog Enricher injecting some data from a dependency. How can autofac inject my dependency into an enricher? This is my container setup: builder.Register((c, p) => { return new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.With<MyEnricherWhichCanAddMoreDataFromADependency>() // ... .CreateLogger(); }).As<ILogger>(); While the enricher would look something like public class MyEnricherWhichCanAddMoreDataFromADependency : ILogEventEnricher { public

Inject a dependency in a SeriLog enricher with autofac

。_饼干妹妹 提交于 2021-02-20 19:05:22
问题 I want to create a Serilog Enricher injecting some data from a dependency. How can autofac inject my dependency into an enricher? This is my container setup: builder.Register((c, p) => { return new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.With<MyEnricherWhichCanAddMoreDataFromADependency>() // ... .CreateLogger(); }).As<ILogger>(); While the enricher would look something like public class MyEnricherWhichCanAddMoreDataFromADependency : ILogEventEnricher { public

asp.net core3.0 mvc 用 autofac

邮差的信 提交于 2021-02-19 02:20:19
好久没有写文章了,最近在用.net core3.0,一些开发中问题顺便记录; 1.首先nuget引入 Autofac Autofac.Extensions.DependencyInjection 2.修改Program.cs 添加.UseServiceProviderFactory(new AutofacServiceProviderFactory()) public class Program { public static void Main( string [] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder( string [] args) => Host.CreateDefaultBuilder(args) .UseServiceProviderFactory( new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup> (); }); } 3.修改Startup.cs 添加 services.AddControllersWithViews()

Autofac ASP.NET Web API (Beta) Integration

╄→гoц情女王★ 提交于 2021-02-19 01:57:36
With the beta release of ASP.NET MVC 4 and the ASP.NET Web API being released a few weeks ago, I decided it was about time to have a look at what the integration story would like for Autofac. The package is available for download on NuGet. Install-Package Autofac.WebApi2 -Version 4.2 . 0 While building the preview of the Web API integration I had the following goals in mind: Ensure that it would work alongside the MVC integration without issues such as naming conflicts. Support both the web hosting and self hosting scenarios in a single assembly. Avoid taking dependencies on the System.Web

autofac &web api 切换数据库

你。 提交于 2021-02-19 01:49:42
https://stackoverflow.com/questions/24188025/is-there-another-way-of-changing-database-instance-in-autofac WebAPI: Retrieve GET parameter from Controller Constructor The constructor is invoked too early, you can't access the parameters from there. However, you can override the Initialize method and retrieve the GET parameters from the context: protected override void Initialize ( HttpControllerContext controllerContext ) { foreach ( var parameter in controllerContext . Request . GetQueryNameValuePairs ()) { Debug . WriteLine ( string . Format ( "{0} = {1}" , parameter . Key , parameter . Value

Given a ContainerBuilder, can I register a missing dependency handler?

我的未来我决定 提交于 2021-02-18 21:27:12
问题 I am trying to make a method with the following signature: void Chain(ContainerBuilder builder, IServiceProvider fallbackServiceProvider) { // ... } The idea is that Chain can be used as follows: IServiceProvider fallbackProvider = someExternalProvider; var builder = new ContainerBuilder(); // Custom registration might happen before and/or after the call to Chain builder.Register<MyCustomService>().As<IMyCustomService>(); builder.Register<MyExternalServiceReplacement>.As<IExternalService>();

Given a ContainerBuilder, can I register a missing dependency handler?

ぃ、小莉子 提交于 2021-02-18 21:26:32
问题 I am trying to make a method with the following signature: void Chain(ContainerBuilder builder, IServiceProvider fallbackServiceProvider) { // ... } The idea is that Chain can be used as follows: IServiceProvider fallbackProvider = someExternalProvider; var builder = new ContainerBuilder(); // Custom registration might happen before and/or after the call to Chain builder.Register<MyCustomService>().As<IMyCustomService>(); builder.Register<MyExternalServiceReplacement>.As<IExternalService>();

Given a ContainerBuilder, can I register a missing dependency handler?

南楼画角 提交于 2021-02-18 21:26:10
问题 I am trying to make a method with the following signature: void Chain(ContainerBuilder builder, IServiceProvider fallbackServiceProvider) { // ... } The idea is that Chain can be used as follows: IServiceProvider fallbackProvider = someExternalProvider; var builder = new ContainerBuilder(); // Custom registration might happen before and/or after the call to Chain builder.Register<MyCustomService>().As<IMyCustomService>(); builder.Register<MyExternalServiceReplacement>.As<IExternalService>();

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

天大地大妈咪最大 提交于 2021-02-11 13:10:12
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

牧云@^-^@ 提交于 2021-02-11 13:10:05
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,