castle-windsor

Castle: How can i get the correct ILogger in the logging interceptor?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 11:11:30
问题 If you are using the LoggingFacility in Castle Windsor the container will automatically resolve the logger associated with your class if you have optional logger dependencies in your class (an ILogger property that castle can inject the logger into), but how can I leverage the facility if I want to implement the logging using AOP (interceptor approach)? I basically want to write something like: public void Intercept(IInvocation invocation) { ILogger logger = LogManager.GetLogger(invocation

Register an Interceptor with Castle Fluent Interface

跟風遠走 提交于 2019-12-10 10:46:41
问题 I am trying to implement nhibernate transaction handling through Interceptors and couldn’t figure out how to register the interface through fluent mechanism. I see a Component.For<ServicesInterceptor>().Interceptors but not sure how to use it. Can someone help me out? This example seemed a little complex. 回答1: You do it in two steps: You need to register the interceptor as a service in the container: container.Register(Component.For<MyInterceptor>()); You register the component you want to

Passing parameters to UsingFactoryMethod in Castle Windsor

霸气de小男生 提交于 2019-12-10 09:56:46
问题 How do I pass dynamic parameters to a UsingFactoryMethod registration? For example, I want to write something like: container.Register( Component.For<IFoo>() .UsingFactoryMethod(return DoSomethingAndReturnInstance(paremeter))); I need the parameters to be sent at runtime, like this: container.Resolve<IFoo>(new { parameter = value }); How can it be done? 回答1: CreationContext.AdditionalParameters has the values you pass to Resolve 回答2: You just have to use container.Register( Component.For<IFoo

How to use Castle Windsor's PerWebRequest lifestyle with OWIN

不打扰是莪最后的温柔 提交于 2019-12-10 04:34:02
问题 I am converting an existing ASP .Net Web API 2 project to use OWIN. The project uses Castle Windsor as the dependency injection framework with one of the dependencies set to use the PerWebRequest lifestyle. When I make a request to the server I get a Castle.MicroKernel.ComponentResolutionException exception. The exception recommends adding the following to the system.web/httpModules and system.WebServer/modules sections in the config file: <add name="PerRequestLifestyle" type="Castle

Generating interface implementation at runtime

不问归期 提交于 2019-12-10 00:31:00
问题 I would like to ask is there a library which allows to generate implementation of interface at runtime with some additional features illustrated below. Let's say I have interface like that: interface ICustomer { string Name {get;set;} string IAddress { get;set; } } interface IAddress { string Street {get;set;} } I would like to do something like that: ICustomer customer = someLibrary.Create<ICustomer>(bool createSubObjects) where Create<T>() method would create an implementation like this at

WPF + Castle Windsor + MVVM: Locator-DataContext

前提是你 提交于 2019-12-09 23:55:26
问题 Edit: I have found one method to do this but I'm not sure if it is the best way. In WindsorContainer initialization, first I register viewmodel: container.Register(Component.For<CentrosViewModel>().LifeStyle.Transient); and later I register the View container.Register(Component.For<CentrosAdminView>().LifeStyle.Transient.DependsOn(Property.ForKey("DataContext") .Eq(ViewModelLocator.Centrosviewmodel))); And definition of property ViewModelLocator.Centrosviewmodel is: public static CentrosModel

WCF Service Library hosted as a Windows Service using Castle.Windsor 3.0 issue

99封情书 提交于 2019-12-09 23:25:37
问题 I am wanting to host my WCF Service Library in a windows service. Although it will be communicating to another wcfservice over a local network. I am having great difficulty in finding recent, up-to-date documentation or help to configure the solution for this purpose. Can anyone advise: a) What the preferred endpoint for this kind of connection? (The other WCF service is hosted using a basicHttpBinding) - this in itself lends itself well to configuring the Castle container through hijacking

Castle Windsor problem

主宰稳场 提交于 2019-12-09 19:12:05
问题 I have a problem with castle core, i'm trying to inject two different database connection to specific repositories. public class Repository1 { public Repository1(System.Data.Common.DbConnection conn) { } } public class Repository2 { public Repository2(System.Data.Common.DbConnection conn) { } } Now for example im would like to inject Mysql connection to Repository1 and Oracle connection to repository2. 回答1: Something like this: container.Register(Component .For<DbConnection>() .ImplementedBy

NHibernate (3.1.0.4000) NullReferenceException using Query<> and NHibernate Facility

我怕爱的太早我们不能终老 提交于 2019-12-09 16:25:55
问题 I have a problem with NHibernate, I can't seem to find any solution for. In my project I have a simple entity (Batch), but whenever I try and run the following test, I get an exception. I've triede a couple of different ways to perform a similar query, but almost identical exception for all (it differs in which LINQ method being executed). The first test: [Test] public void QueryLatestBatch() { using (var session = SessionManager.OpenSession()) { var batch = session.Query<Batch>()

Why is CastleWindsor's BeginScope out of scope?

若如初见. 提交于 2019-12-09 15:32:15
问题 I'm trying to add Castle Windsor to my Web API project, and am following this post, but am getting a compile-time error on this line of code: this._scope = container.BeginScope(); ...as " 'Castle.Windsor.IWindsorContainer' does not contain a definition for 'BeginScope' and no extension method 'BeginScope' accepting a first argument of type 'Castle.Windsor.IWindsorContainer' could be found (are you missing a using directive or an assembly reference?) " Here is the entire code so that it can be