castle-windsor

Castle Windsor Dependency Injection - restore dependencies for existing instance

好久不见. 提交于 2019-12-08 06:15:11
问题 I have a fairly straight-forward scenario that I am trying to solve but I'm hitting a few brick walls with Windsor - perhaps I'm trying to solve the problem in wrong way? I have a type called Foo as follows: public class Foo { [NonSerialized] private IBar bar; public IBar Bar { get { return this.bar; } set { this.bar = value; } } public Foo(IBar bar) { } } I instantiate via the container in the normal way: var myFoo = container.Resolve<Foo>(); The dependency IBar is registered with the

Dependency on Log4Net Logger and Retrieve Logger by Caller Type using Castle Windsor

不问归期 提交于 2019-12-08 05:38:22
I have a thin wrapper around log4net and I am trying to use the type of the calling class to get a logger from log4net.LogManager by using Castle.Windsor . public class Foo: IFoo { private readonly ICommonLog _logger; public Foo(ICommonLog logger) { _logger = logger; } public void FooBar() { _logger.Info("Enter FooBar Method"); } } public class CommonLog : ICommonLog { private readonly log4net.ILog _logger; public CommonLog(Type loggerType) { _logger = log4net.LogManager.GetLogger(loggerType); } public void Info(string message) { _logger.Info(message.Cleanse()); } // ... } I have tried this

Castle Windsor: auto-register types that have dependency in constructor

穿精又带淫゛_ 提交于 2019-12-08 05:30:23
问题 Most of the examples I see for Castle Windsor auto-register type that derive from some IFoo. However, I often have simple components (services) that just required IFoo in the constructor: public class Service { public Service(Service2 service, IFoo foo) {} } public class Service2 { public Service2(IFoo foo) {} } How do I make Windsor automatically register/recognize them? I see two ways: Browse all types in assembly, get their constructors, check if any of the constructor's parameter is

How can I decouple my application from my membership service?

限于喜欢 提交于 2019-12-08 03:36:47
问题 I'm working on an ASP.NET MVC 4 project that uses Castle Windsor. One of the controllers has a dependency on MembershipService: public class FooController : Controller { private readonly MembershipService MembershipService; public FooController( MembershipService membershipService ) { MembershipService = membershipService; } [Authorize( Roles = "Administrator" )] public ActionResult DoSomething() { var user = MembershipService.GetUser( User.Identity.Name ); // etc... } } When I started

Inject logging dependency with Castle Windsor

梦想的初衷 提交于 2019-12-08 03:30:12
问题 I was trying to inject logging dependency by Castle Windsor to my code. More precisely, whenever a method in a class throws an error or application flow enters into a method it simply logs into a file. How to do this by writing nothing like logger.Debug("Error code"); in the methods explicitly for each of the methods. Suppose we add attribute on each of the class or methods to leverage the logging facility for that. Thanks in advance. 回答1: Use the interceptor facility in Castle Windsor. So

Castle Windsor - how to resolve by name?

醉酒当歌 提交于 2019-12-08 03:19:06
问题 My application uses the "SignalR" client/server comms framework. If you aren't familiar with it, the server-side app typically contains one or more "hub" classes (similar to asmx web services), each providing methods that can be called by a client. During startup, the client needs to first create a connection, then create a "proxy" for each hub that it will need to talk to, e.g.:- var hubConnection = new HubConnection("http://..."); var fooHubProxy = hubConnection.CreateHubProxy("FooHub");

Generic repository lifetime configuration with Windsor

孤者浪人 提交于 2019-12-08 02:41:47
问题 I'm out of ideas how to configure right Windsor container for use with repositories in Windows app. I have generic repository implementation Repository, where T is entity type, it has a dependency IDatacontextProvider, which provides datacontext for it: public class Repository<T> : IRepository<T> where T : class { protected DataContext DataContext; public Repository(IDataContextProvider dataContextProvider) { DataContext = dataContextProvider.DataContext; } .... } And for simple things

Castle windsor and IHttpHandler and IHttpHandlerFactory

我的未来我决定 提交于 2019-12-08 02:03:52
问题 I'm developing a RIA application where there is javascript on the client (i'm using Ext) and .NET on the server, for json-rpc I'm using Jayrock which is a nice library (at least for me) as it is simple and works well, Ive used it in the past. Jayrock uses Web Handlers to serve the json-rpc request, you code a class that implements IHttpHandler and derives from a Jayrock class with some attributes, and it does the rest to provide a javascript class to the browser to do its magic. Now, normally

Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

 ̄綄美尐妖づ 提交于 2019-12-08 00:31:27
问题 This isn't a very simple question, but hopefully someone has run across it. I am trying to get the following things working together: MVC2 FluentValidation Entity Framework 4.0 (POCO) Castle Windsor I've pretty much gotten everything working. I have Castle Windsor implemented and working with the Controllers being served up by the WindsorControllerFactory that is part of MVCContrib. I also have Castle serving up the FluentValidation validators as is described by this article: http://www

Using Client-Side Task-Based Operations with WCFFacility in Castle.Windsor

ぐ巨炮叔叔 提交于 2019-12-08 00:29:32
问题 I would like to take advantage of the new task-based operations for a WCF client. I am currently using the WCFFacility as follows: container.Register(Component .For<IAdminService>() .LifeStyle.Transient .AsWcfClient(new DefaultClientModel() { Endpoint = WCFHelpers.BasicHttp(settings.MaxReceivedMessageSize) .At(addr) })); where IAdminService is the ServiceContract class. All the MSDN articles about task-based operations refer to setting a 'task based operations' tick box when importing the