ioc-container

How to do dependency injection to Action Filter on ASP.NET Web API

為{幸葍}努か 提交于 2020-01-12 04:06:29
问题 I really get stuck on the approach to do dependency injection into action filter of web api. I have an action filter like this: public class AuthorizationAttribute : ActionFilterAttribute { public IApiKeyRepository Repository { get; set; } private Guid GetApiKey(string customerKey) { return Repository.GetApiKey(customerKey); } public override void OnActionExecuting(HttpActionContext actionContext) { } } I would like to do property injection on the property Repository by using Windsor (but it

Autofac passing parameter to nested types

心不动则不痛 提交于 2020-01-11 04:59:04
问题 I am using Autofac as my IoC in my WCF service. I have a situation where I want to pass an object to a nested type (ie a type that is not resolved directly, but when resolving another type). As far as I understood, passing this object as a constructor parameter is the preferred way in Autofac. Here is an example of such a situation. The nested type: public class EventLogger<T> : IEventLogger<T> { public EventLogger(IRepository<T> repository, User currentUser) { ... } } The type I am actually

How can I add a Dependency that can be used as type parameter 'TImpl' for Castle Windsor?

僤鯓⒐⒋嵵緔 提交于 2020-01-06 15:32:51
问题 I was getting this runtime exception with a particular URL: " Missing dependency. Component NRBQ.Web.Controllers.DeliveryController has a dependency on SeaStore.Data.Legacy.Interfaces.INRBQDeliveryRepository, which could not be resolved. Make sure the dependency is correctly registered in the container as a service, or provided as inline argument." ExceptionType: "Castle.MicroKernel.Resolvers.DependencyResolverException " ...so I added this code (based on existing code that works) to the IOC

autofac scope around a resolved instance

拈花ヽ惹草 提交于 2020-01-06 05:28:11
问题 I'm somewhat new to autofac, but have already used it successfully with different "simple" configurations. Now I'm trying something more complex and struggle with working this out. Essentially, I have an entry point where all autofac configuration is done and the first objects are resolved, which themselves get dependencies by constructor injection, their dependencies can have other dependencies and so on. Some code: public class Root { public Root(A.Factory factory) { for (int i = 0; i < 3;i

How do i get MEF container to inject himself

早过忘川 提交于 2020-01-05 10:33:25
问题 I'm using constructor injection with MEF Composition Container and I want to know how can I make the CompositionContainer inject itself on the instance of the object he is providing. 回答1: You can use one of the CompositionContainer.ComposeExportedValue methods to create a part from a given object. Here's a sample: class Program { static void Main(string[] args) { var container = new CompositionContainer(new ApplicationCatalog()); Console.WriteLine("Main: container [{0}]", container

InjectableFilterAttribute never hits the Filter

≡放荡痞女 提交于 2020-01-05 07:48:47
问题 On my base controller I have placed the Logger attribute. This LoggerAttribute looks like this: public class LoggerAttribute: InjectableFilterAttribute { public override Type FilterType { get { return typeof (LoggerActionFilter); } } } The ctor on this loggerattribute gets hit, but the FilterType getter not. The relevant part of the filter itself looks like this: public class LoggerActionFilter: IActionFilter { private readonly ILoggerService logger; public LoggerActionFilter (ILoggerService

Castle Windsor Dependency Injection with Multiple Concrete Implementations

流过昼夜 提交于 2020-01-05 05:31:46
问题 Is there a method for Castle Windsor to inject multiple concrete implementations of a single interface into a constructor? I want to do something like this: class Some { public Some(IService[] services) { services.Each(s => s.DoSomething(this)); } } Note, at this level I do not have access to the IWindsorContainer and would like to keep it that way. 回答1: See http://hammett.castleproject.org/?p=257 来源: https://stackoverflow.com/questions/1473665/castle-windsor-dependency-injection-with

Castle Windsor - One class implementing multiple interfaces

我与影子孤独终老i 提交于 2020-01-05 05:29:20
问题 I register my two interfaces on application start as so:- container.Register(Component.For(typeof(IEntityIndexController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); container.Register(Component.For(typeof(ISnippetController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); Then when I try to run an IoC.Resolve on an object that uses the second interface here (ISnippetController) it throws the following exception:- Can't create component 'MyApp.Admin

Autofac registers components multiple times

坚强是说给别人听的谎言 提交于 2020-01-05 04:13:11
问题 In a previous question about got I visualize the graph of my dependencies I got the foundation for the code I now use to visualize my dependency graph as it is resolved by Autofac. Running the code I get a tree that results in code like the following. Usd.EA.Bogfoering.WebApi.Controllers.BogfoerController (3851,7 ms. / 0,0 ms.) Depth: 0 Usd.EA.Bogfoering.WebApi.Controllers.BogfoerController (3851,7 ms. / 0,4 ms.) Depth: 1 Usd.Utilities.WebApi.Controllers.UnikOwinContext (0,1 ms. / 0,0 ms.)

Find class to instantiate by name without namespace or assembly? (.NET)

你。 提交于 2020-01-05 03:09:35
问题 I'd like to instantiate a class by name (a string) without specifying a namespace or assembly. Like this (Unity syntax): var processor = container.Resolve<IProcessor>("SpecialProcessor"); would instantiate the first IProcessor it finds called SpecialProcessor. Maybe MyNamespace.SpecialProcessor I'd like to avoid having to create an entry in a config every time somebody adds a new processor. I'm fine with having an entry for all candidate assemblies though. Can I use an IoC container for