castle-windsor

Why have named logger in Log4Net?

和自甴很熟 提交于 2019-11-29 11:06:59
I have been investigating ways to inject the Log4Net ILog into classes using Castle Windsor. In most examples, I see where Castle Windsor can provide a "facilitator" that provides property injection, and injects the ILogger (not ILog). I have found only one example where contructor injection is used, and the facilitator method is not used (see Castle Windsor dependency injection: Use the caller type as a parameter ) In all these examples, it seems Log4Net wants to have a named logger. Most examples refer to the Log4Net static method LogManager.GetLogger(class name here). This makes it a

Inject a MembershipProvider into ASP.NET MVC AccountController

跟風遠走 提交于 2019-11-29 10:27:21
问题 ASP.NET MVC 1.0 project templates include an AccountController class, which supports constructor injection: public AccountController(IFormsAuthentication formsAuth, IMembershipService service) { FormsAuth = formsAuth ?? new FormsAuthenticationService(); MembershipService = service ?? new AccountMembershipService(); } An AccountMembershipService class is also included, and it too supports constructor injection: public AccountMembershipService(MembershipProvider provider) { _provider = provider

Func<T> injecting with Windsor container

最后都变了- 提交于 2019-11-29 07:59:46
Here is a code excerpt from AspComet project that works with Autofac. public MessageBus(IClientRepository clientRepository, Func<IMessagesProcessor> messagesProcessorFactoryMethod) { this.clientRepository = clientRepository; this.messagesProcessorFactoryMethod = messagesProcessorFactoryMethod; } How can I inject " Func<IMessagesProcessor> messagesProcessorFactoryMethod " with Windsor, is it possible? Thanks. container.Register(Component.For<Func<Foo>>().Instance(f)); Here's a passing unit test that demonstrates the concept: [TestMethod] public void Test2() { Func<string> f = () => "Hello world

Castle, AOP and Logging in .NET

那年仲夏 提交于 2019-11-29 07:00:26
Are there any tutorials or sample programs out there on using AOP, Castle, and logging in a .Net application? I have found pieces out there but I am looking for something more to help me form a more complete picture. Thanks, -Brian You need to be using a custom Interceptor, which inherits from IInterceptor. For example: public class LogInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { Logger.Write("I'm in your method logging your access"); invocation.Proceed(); } } Hopefully this helps. 来源: https://stackoverflow.com/questions/238755/castle-aop-and-logging-in-net

logging in log4net to different appenders based on circumstances

左心房为你撑大大i 提交于 2019-11-29 06:38:40
I am using log4net and in one class require logging to a RollingFile appender, but then in another class, I wish to log to the event log + rolling file + console appender. What is the best practice? and could I see some sample code? By the way to make things more difficult, I am using Castle Windsor Logging Facility with Log4net to resolve my Logger instance. If it helps, I was thinking this below, but have no idea if this is best practice, or how to activate a particular logger based on 'name' still utilising my current logger instance from windsor: log4net.config: ... <logger name=

Applying AOP

我是研究僧i 提交于 2019-11-29 06:01:04
I've been using some basic AOP style solutions for cross-cutting concerns like security, logging, validation, etc. My solution has envolved around Castle Windsor and DynamicProxy. I've gone down this route because I can apply everything using a Boo based DSL and keep my code clean of Attributes. I was told at the weekend to have a look at PostSharp as it's supposed to be a "better" solution. I've had a quick look at PostSharp, but I've been put off by the Attribute usage. Has anyone tried both solutions and would care to share their experiences? I only looked at castle-windsor for a short time

Register types based on base class

天涯浪子 提交于 2019-11-29 05:18:40
I'm trying to figure out Windsor as an IOC container. The problem I'm facing right now is to register all of my viewmodels at once. I've taken a look at the docs and thought that the following code should work. However, when I check the container afterwards, nothing is registered. container.Register(Classes.FromThisAssembly() .BasedOn<ViewModelBase>() .LifestyleTransient()); where ViewModelBase is my baseclass. Also tried the following: container.Register(Classes.FromThisAssembly() .InSameNamespaceAs<MainWindowViewModel>() .LifestyleTransient()); The necessary dependencies can be resolved, the

Castle Windsor intercept method call from within the class

家住魔仙堡 提交于 2019-11-29 05:14:54
We have components registrations in Castle Windsor container like so void RegisterComponent<TInterface, TImplementation>() { var component = Component.For<TInterface>().ImplementedBy<TImplementation>(); component.Interceptors<SomeInterceptor>(); container.Register(component); } However we got to the problem that when we do a method call from within the class it does not get intercepted. For example we have component like ServiceA : IService { public void MethodA1() { // do some stuff } public void MethodA2() { MethodA1(); } } And if we call MethodA2 or MethodA1 methods from some other class it

Castle Windsor register class with constructor parameters

守給你的承諾、 提交于 2019-11-29 05:11:48
问题 I have the following class: public class DatabaseFactory<C> : Disposable, IDatabaseFactory<C> where C : DbContext, BaseContext, new() { private C dataContext; private string connectionString; public DatabaseFactory(string connectionString) { this.connectionString = connectionString; } public C Get() { return dataContext ?? (dataContext = Activator.CreateInstance(typeof(C), new object[] {connectionString}) as C); } protected override void DisposeCore() { if (dataContext != null) dataContext

What is the best practice to implement multi tenancy in ASP.NET MVC using Castle Windsor?

旧巷老猫 提交于 2019-11-29 04:18:41
问题 I have a service with two different implementations and I would like to inject into the controllers constructor, depends on a criteria (at the moment the criteria is a simple value stored in session). Here is what I got now... Service interface: public interface IService { string GetSampleText(); } Implementation #1: public class FirstService : IService { string GetSampleText() { return "First Service"; } } Implementation #2: public class SecondService : IService { string GetSampleText() {