FAQ Database Discussion Community


NUnit keeps running the wrong version of a .dll

c#,nunit,inversion-of-control,castle-windsor,nlog
I am using the NUnit 2.6.4 test runner. I am running from an .nunit project file that loads my .csproj test. It keeps running the wrong version of a dependency. Background: I have castle windsor 3.3 using the NLog facility. I am using NLog 3.2. By default Windsor tries to...

Nhibernate sessionPerThread

c#,nhibernate,concurrency,castle-windsor
I am creating entities in with multiple thread at the same time. When i do this in sequence order (with one thread) everything is fine, but when i introduce concurrency there are pretty much always new exception. i call this method asynchronously: public void SaveNewData(){ ....DO SOME HARD WORK.... var...

Can't resolve dependencies in Web Api Controller

c#,asp.net,castle-windsor,web-api,owin
I have a Web Api with owin and Windsor. Get next error: An error has occurred.An error occurred when trying to create a controller of type 'DBManagerController'. Make sure that the controller has a parameterless public constructor.System.InvalidOperationException at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) at...

What's the equivalent of CastleWindsor's container.Release in LightInject?

asp.net-web-api,dependency-injection,castle-windsor,light-inject
I saw ASP.NET Web API dependency injection in Seemann's site. It uses CastleWindsor though. request.RegisterForDispose( new Release( () => this.container.Release(controller))); What's the equivalent of CastleWindsor's container.Release in LightInject? http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/...

Is this dependency of a Windsor singleton thread-safe?

c#,multithreading,async-await,castle-windsor
I'm not an expert on async programming by any means so I want to verify I have an issue. I have a Web API app that uses Castle Windsor but also uses the built-in HttpConfiguration.Services pipeline for certain ASP.NET functions. In this case I'm registering a global exception handler. Here's...

Decorate each item resolved in a collection with Castle Windsor

collections,castle-windsor,decorator
Suppose I have an interface with multiple base implementations: interface IPrinter { void Print(); } class Printer1 : IPrinter { public void Print() { Console.WriteLine(GetType()); } } class Printer2 : IPrinter { public void Print() { Console.WriteLine(GetType()); } } I also have a decorator implementation: class ModifyingPrinter : IPrinter {...

OAuth: ASP.NET Web API User.Identity doesn't load claims set by authentication token provider

authentication,asp.net-web-api,oauth,castle-windsor,claims-based-identity
I am using OAuth bearer authentication, configured like this in Startup.cs: OAuthBearerAuthenticationOptions oAuthBearerOptions = new OAuthBearerAuthenticationOptions { AccessTokenProvider = new AccessTokenProvider(), AuthenticationMode = AuthenticationMode.Active }; app.UseOAuthBearerAuthentication(oAuthBearerOptions); ... where AccessTokenProvider is implemented as: public class AccessTokenProvider : AuthenticationTokenProvider { public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { // Internal logic to get...

Which Namespace holds Component.For in Castle Windsor?

c#,castle-windsor
I'm learning Castle Windsor and I found this tutorial. In it, there's this code: private void button1_Click(object sender, EventArgs e) { // CREATE A WINDSOR CONTAINER OBJECT AND REGISTER THE INTERFACES, AND THEIR CONCRETE IMPLEMENTATIONS. var container = new WindsorContainer(); container.Register(Component.For<Main>()); container.Register(Component.For<IDependency1>().ImplementedBy<Dependency1>()); container.Register(Component.For<IDependency2>().ImplementedBy<Dependency2>()); // CREATE THE MAIN OBJECT AND INVOKE...

Resolving Interface with generic type constraint with Castle Windsor

c#,generics,castle-windsor
Given the interface where FooRequest and FooResponse are abstract: public interface IFooHandler<TRequest, TResponse> where TRequest : FooRequest where TResponse : FooResponse { TResponse CheckFoo(TRequest request); } An implementation of: public class MyFooHandler : IFooHandler<MyFooRequest, MyFooResponse> { public MyFooResponse CheckFoo(MyFooRequest request) { /* check for foos */ } } How would...

Castle Windsor DI installer: dependency factory method has nested dependency on ApiController property

asp.net-web-api,dependency-injection,inversion-of-control,castle-windsor,ioc-container
I am trying to implement DI with Castle Windsor. Currently I have a controller with overloaded constructors like this (this is an antipattern as described here: https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=97): public class MyController : ApiController { protected IStorageService StorageService; protected MyController() { StorageService = StorageServiceFactory.CreateStorageService(User.Identity as ClaimsIdentity); } protected MyController(IStorageService storageService) { StorageService...

How do I intercept Castle Windsor's component resolution to override dependencies?

c#,dependency-injection,inversion-of-control,castle-windsor
I'm looking for a way to hook into Castle Windsor's resolution process so that I can do something like: if (componentCanBeResolvedElsewhere) { return elsewhere.Resolve<TService>(); } else { windsorContainer.Resolve<TService>(); } I want Castle Windsor to handle the majority of my dependencies, but I want to provide an ability to 'fill-in the...

Castle Windsor Property Injection with paramters

dependency-injection,castle-windsor
I am new to this so I appreciate the help. I am using Castle Windsor as my container with XML config. For several of my core services this works perfectly, I simply declare a public property named the same thing and it injects it as expected. Most of my core...

Host WCF service using top shelf and windsor castle

c#,wcf,castle-windsor,topshelf,windsor-facilities
I am using Topshelf to run my wcf service and windsor castle for dependency injection. Problem it when I run the host program directly, it runs fine as console host but the same program gives this error while trying to start it as windows service. Topshelf.Hosts.StartHost Error: 0 : The...

Castle Windsor Interceptors and Registering by Convention

c#,castle-windsor,interceptor
I'm currently using Castle Windsor to manage dependencies for my application. I'm currently using the Classes.FromAssemblyContaining to register all components of a given type IFoo<> and would like to register an interceptor for all of these classes. I can get the interceptor to work when I register individual components like...

Castle Windsor / ActiveRecord / NHibernate: How to intercept/modify connection string

c#,nhibernate,connection-string,castle-windsor,castle-activerecord
I have consolidated the connection string information for a number of C# .NET solutions that are in my possession. Previously, each project was storing its connection string in its own format, requiring me to modify several files for each installation of the software. Only one remaining solution is giving me...

Castle Windsor Installers with constructor parameters

castle-windsor,ioc-container,castle
I have the following class. public class NHibernateInstaller : IWindsorInstaller { private string _overrideConnectionstring; private IPersistenceConfigurer _persistenceConfigurer; private static IPersistenceConfigurer _defaultConfiguration; public IPersistenceConfigurer PersistenceConfigurer { get { return _persistenceConfigurer ?? (_persistenceConfigurer = MsSqlConfiguration.MsSql2008 .ConnectionString(Config.DefaultConnection)); } protected set { if (value == null) { throw new ArgumentNullException("value"); } if (_persistenceConfigurer !=...

Check if Windsor has a matching component registered

castle-windsor
In a Castle Windsor scenario I want to check if my container has a certain service registered, and do basically if (container.HasComponentFor<IMyService>()) { // resolve service with container.Resolve<IMyService>() // then do cool stuff } but of course, container.HasComponentFor<IMyService>() doesn't exist. Is there an equivalent?...

How to measure invocation time of “Handle” method in NServiceBus?

c#,castle-windsor,nservicebus,stopwatch,nservicebus5
I need to measure invocation time of Handle method in every instance of IHandleMessages<> interface. I tried to use Interceptor of Castle Windsor, public class NsbHandlerMeasurementInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { if (invocation.Method.Name == ExpressionExtender.GetMethodName<IHandleMessages<DummyType>>(b => b.Handle(null))) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); invocation.Proceed(); stopwatch.Stop(); //...

Castle.Windsor IoC-container specific configuration

c#,dependency-injection,inversion-of-control,castle-windsor,ioc-container
I have chosen Castle.Windsor as IoC container for my app. This is my first IoC expirience so I need an advice configuring it. The root class of the app is Scheduler. It plans and performs different kinds of "jobs". Each job implements IWorker interface, so I decided to inject a...

AutoFac constructor multiple Interface

c#,.net,model-view-controller,castle-windsor,autofac
I am using Autofac in my project. I want to use a simple interface to resolve them. Not generic repository. I was using Castle in my old projects. It has a class which have static methods. I used it in my constructor method like this; IService.ProductService.GetMyProducts(); In Autofac i couldnt...

Castle Windsor WCF client generation with differing addresses

c#,wcf,castle-windsor
I'm using castle windsor wcf facility to create clients with the code below. I would like to be able to dynamically set "mypath" to something different for each client proxy thats created. I have a feeling this could be done with a typed factory and passing the string as a...

Load Heavy Object from IoC Container blocks the UI

c#,wpf,nhibernate,async-await,castle-windsor
We have a WPF application (.NET 4.0, can't change due to Windows Server 2003 and XP compatibility) using BCL to support async/await. For DI and aspects we use Castle IoC and, to access the Oracle databases, we use NHibernate. Our problem is the following: I have implemented a UoW pattern...

Castle Windsor & Command Pattern

c#,dependency-injection,inversion-of-control,castle-windsor
I am trying to implement a Command, CommandHandler and CommandDispatcher pattern using Castle Windsor without manually asking the container to resolve a CommandHandler based on Command type (which is generally considered an anti-pattern). I found this old article, but the implementation of ITypedFactoryComponentSelector has changed, so now it returns a...

Castle Windsor Lifestyle for EF DbContext Needed For Logging After Web API Request

c#,entity-framework,asp.net-web-api,dependency-injection,castle-windsor
I am using Castle Windsor for a DI container for Web API 2 and some of my controllers have EF DbContext dependencies, which I am injecting using the following CW installers (this part works fine): public class ApiControllerInstaller : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Classes.FromThisAssembly().BasedOn<ApiController>().LifestylePerWebRequest()); }...