castle-windsor

How can I override a component registered in Castle Windsor?

时光毁灭记忆、已成空白 提交于 2019-12-05 22:20:52
I'm just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want to be able to register a component which implements a base class, and use a container to resolve the implementer. So far, using container.Register(Component.For<LoggerBase>().ImplementedBy<DebugLogger>()); and container.Resolve<LoggerBase>(); In my tests, I'd like to add a stub/mock implementation to override the "DebugLogger" implementation so that when my prod code calls container.Resolve

Is this a good solution to handle NHibernate Isession as PerWebRequest

北慕城南 提交于 2019-12-05 20:57:13
I Have been struggeling with NHibernate session management and have now ended up with two possible solutions to meet a session per web request. I'm using Windsor for IoC in an ASPNET mvc project First solution is to open a session in begin_request and close/dispose it again in end_request. In Windsor setup I would have container.Register(Component.For().UsingFactoryMethod(() => SessionFactory.GetCurrentSession()).LifeStyle.Transient; This solution creates the session per request and shares it through GetCurrentSession. The second solution is to use Windsor like container.Register(Component.For

Intercept Properties With Castle Windsor IInterceptor

爷,独闯天下 提交于 2019-12-05 20:40:58
Does anyone have a suggestion on a better way to intercept a properties with Castle DynamicProxy? Specifically, I need the PropertyInfo that I'm intercepting, but it's not directly on the IInvocation, so what I do is: public static PropertyInfo GetProperty(this MethodInfo method) { bool takesArg = method.GetParameters().Length == 1; bool hasReturn = method.ReturnType != typeof(void); if (takesArg == hasReturn) return null; if (takesArg) { return method.DeclaringType.GetProperties() .Where(prop => prop.GetSetMethod() == method).FirstOrDefault(); } else { return method.DeclaringType

Castle Windsor - how to resolve components based on constructor parameters

ぃ、小莉子 提交于 2019-12-05 19:23:53
问题 Say I have a component like this public class MyComponent { public MyComponent(string name) { } } I basically want to have the provided constructor parameters behave as part of the component identifier when resolving it. If you've never resolved it with that set of parameters, it will instantiate a new one. In other words, I want to somehow modify the following test to succeed: IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<MyComponent>()); MyComponent

Windsor + NHibernate + ISession + MVC

瘦欲@ 提交于 2019-12-05 15:56:47
I am trying to get Windsor to give me an instance ISession for each request, which should be injected into all the repositories Here is my container setup container.AddFacility<FactorySupportFacility>().Register( Component.For<ISessionFactory>().Instance(NHibernateHelper.GetSessionFactory()).LifeStyle.Singleton, Component.For<ISession>().LifeStyle.Transient .UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession()) ); //add to the container container.Register( Component.For<IActionInvoker>().ImplementedBy<WindsorActionInvoker>(), Component.For(typeof(IRepository<>))

Linq to SQL DataContext Windsor IoC memory leak problem

一世执手 提交于 2019-12-05 15:45:26
I have an ASP.NET MVC app that creates a Linq2SQL datacontext on a per-web-request basis using Castler Windsor IoC. For some reason that I do not fully understand, every time a new datacontext is created (on every web request) about 8k of memory is taken up and not released - which inevitably causes an OutOfMemory exception. If I force garbage collection the memory is released OK. My datacontext class is very simple: public class DataContextAccessor : IDataContextAccessor { private readonly DataContext dataContext; public DataContextAccessor(string connectionString) { dataContext = new

Architecture problem: use of dependency injection resulting in rubbish API

送分小仙女□ 提交于 2019-12-05 11:15:55
I'm tring to create a class which does all sorts of low-level database-related actions but presents a really simple interface to the UI layer. This class represents a bunch of data all within a particular aggregate root, retrieved by a single ID int. The constructor takes four parameters: public AssetRegister(int caseNumber, ILawbaseAssetRepository lawbaseAssetRepository, IAssetChecklistKctcPartRepository assetChecklistKctcPartRepository, User user) { _caseNumber = caseNumber; _lawbaseAssetRepository = lawbaseAssetRepository; _assetChecklistKctcPartRepository = assetChecklistKctcPartRepository

IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

强颜欢笑 提交于 2019-12-05 10:38:00
UPDATE: In Windsor 2.5 the assembly name is Castle.Windsor not Castle.MicroKernel I'm trying to deploy an ASP.NET MVC app to IIS7 and I'm getting this error: Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '' to the section on your web.config My httpModules contains: <httpModules> <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"/> </httpModules> system.webServer handlers section contains <handlers> <remove name="PerRequestLifestyle"/> <add name=

ravendb, castle IoC ,Wcf facility - doc session liefstyle

a 夏天 提交于 2019-12-05 10:14:10
What's the recommended lifestyle for raven doc session and store under a windsor ioc, wcf facility setup hosted in IIS? I keep seeing this error: Error TempPathInUse (JET_errTempPathInUse, Temp path already used by another database instance)` here is my setup: public class RavenInstaller : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( Component.For<IDocumentStore>().ImplementedBy<DocumentStore>() .DependsOn(new { connectionStringName = "RavenConnectionString" }) .OnCreate(DoInitialisation) .LifeStyle.Singleton, Component

System.InvalidProgramException when executing unit tests in MSTest after Microsoft Security update MS13-004

穿精又带淫゛_ 提交于 2019-12-05 08:03:43
After applying the Microsoft Security update on the 8th of January 2013 http://technet.microsoft.com/en-us/security/bulletin/ms13-004 we have started to experience failures in our CI builds on our build servers and locally when running tests on our development boxes. We get a System.InvalidProgramException: Common Language Runtime detected an invalid program . This only happens when running tests using MSTest that make use of Castle Windsor DynamicProxy although I am not convinced DynamicProxy is at fault here. An example piece of code that would generate the exception is below. [TestMethod]