autofac

When using autofac, how do I use a WebAPI controller type name as a parameter to a depencency's Register?

走远了吗. 提交于 2019-12-08 08:43:28
问题 I'm using autofac and trying to register WebApi controllers. Each controller takes a unique Logging.ILog as a constructor parameter (this is my ILog adapts to the log4net ILog). When loggers are resolved I would like them to be named according to the controller they are being resolved for. Something like this: builder.Register(c => log4net.LogManager.GetLogger("NEED CONTROLLER NAME HERE")); builder.Register(c => new Logging.Adapters.Log4NetAdapter(c.Resolve<log4net.ILog>())); builder

C#, Autofac: NamedParameter is not provided in Register<>

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:33:02
问题 I'm trying some autofac features at the moment and are struggling with the NamedParameter. I created a very simple example, where IFoo is realized by HappyFoo and SadFoo . IFooUser expects an IFoo object in the constructor and uses it to print something to the console. The code below shows how I'm trying to build a IFooUser object which shall use an IFoo object based on a 'score' value. var builder = new ContainerBuilder(); builder.RegisterType<NormalFooUser>().As<IFooUser>(); builder

Autofac parameter passing

痞子三分冷 提交于 2019-12-08 07:53:13
问题 I've been trying to integrate the latest version of autofac (1.3.3.54), and I'm running into the following problem. The recommended way of consuming parameters in the Register callback, per the Google code wiki for the project is as follows: builder.Register((c, p) => new Foo(p.Get("arg1"))); However this won't compile with the mentioned version of the autofac code. I looked through the source and I see that p is an IEnumerable (ComponentActivatorWithParameters). Is the code out of date with

Interception on .NET Core 2.0 Web API Controller By Using Autofac

泄露秘密 提交于 2019-12-08 07:29:27
问题 I am trying to use interceptions on .Net Core 2.0 WebApi Application by using Autofac but I couldnt succeed it on Controllers. What I try is First I created a basic webapi which has one default controller(ValuesController). Then I set up the autofac configuration as below. Project is working without any error, but interception doesnt seems to be running. What I am doing wrong ? Startup.cs public void ConfigureContainer(ContainerBuilder builder) { builder.Register(c => new CallLogger());

What is the best way to manage Transaction with Nhibernate Repository

 ̄綄美尐妖づ 提交于 2019-12-08 07:06:58
问题 Actually i try to found the best way to manage Transaction with Nhibernate with Repository pattern in MVC 5 context You can found my sample project here: https://github.com/Nono31/Pixel.Sample My repository called by manager And my manager was called by controller Actually all works fine, but when I start NHProfiler, I have a warning "Use of implicit transactions is discouraged" (http://www.hibernatingrhinos.com/products/nhprof/learn/alert/donotuseimplicittransactions) My question is how to

Issue registering generic types with Autofac in ASP.NET Core

你说的曾经没有我的故事 提交于 2019-12-08 05:28:25
问题 I'm a relatively new user of both Autofac and ASP.NET Core. I've recently ported a small project from a 'classic' ASP.NET WebAPI project to ASP.NET Core. I am having trouble with Autofac, specifically in registration of generic types. This project uses a Command pattern, each command handler is a closed generic like public class UpdateCustomerCommandHandler: ICommandHandler<UpdateCustomerCommand> These command handlers are injected into the controllers like: readonly private ICommandHandler

Multiple navigation control through dependency injection

淺唱寂寞╮ 提交于 2019-12-08 05:04:17
问题 My base content class. I used this class as a theme for my project. I do not know this info relevant or not. In here I create an abstract method that would overload the navigation method. public abstract class BaseContentPage : ContentPage { public readonly BaseViewModel BaseViewModel; public BaseContentPage(BaseViewModel baseViewModel) { BaseViewModel = baseViewModel; } public abstract void Navigate(SelectedItemChangedEventArgs e); } In my locator where I build the dependency Injection

Identify the dependency resolving an instance - IoC (autofac)

青春壹個敷衍的年華 提交于 2019-12-08 04:05:51
问题 Is there a way to identify which caller/dependency is resolving an instance that it is dependent on? here is what I am thinking public class A { public A() { Console.Write("I am being resolved by {0}"); } } public class B { public B(A a) { //Should print: A being resolved by B } } public class C { public C(A a) { //Should print: A being resolved by C } } I am guessing for a single instance that is shared across multiple dependency it might be a little tricky but I am specifically looking for

Including Autofac.Module in custom module breaks Orchard

空扰寡人 提交于 2019-12-08 03:52:40
问题 See here & here for why I'm trying to do this. I have a custom module that I'm building (and which is it's own .csproj in the Orchard .sln, as normal) I have a (relatively complex) dependency that I wish to inject into Orchard. Currently if I build and run the code it's perfectly happy until it hits my dependency at which point it null-refs (as I'd expect it to). I can access the admin site and any pages that don't reference the dependency. I add a reference to Autofac to my project. -> All

Updating property of a singleton with Thread Safety

旧街凉风 提交于 2019-12-08 03:47:32
问题 Our setup is: Asp.NET + MVC5 using AutoFac for DI. We have a class (which is a singleton) which is managing the access tokens for a variety of services. Every now and then, these tokens get too close to expiry (less then 10 minutes) and we request new tokens, refresh them. My current implementation looks like this: // member int used for interlocking int m_inter = 0; private string Token { get; set; } private DateTimeOffset TokenExpiry { get; set; } public SingletonClassConstructor() { //