Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Facilities / Logging / Castle.Facilities.Logging / LoggerResolver.cs
blob2e5976d20cd9fec0c17490f5de1529874b943b66
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Facilities.Logging
17 using System;
18 using Castle.Core;
19 using Castle.Core.Logging;
20 using Castle.MicroKernel;
22 /// <summary>
23 /// Custom resolver used by the MicroKernel. It gives
24 /// us some contextual information that we use to set up a logging
25 /// before satisfying the dependency
26 /// </summary>
27 public class LoggerResolver : ISubDependencyResolver
29 private ILoggerFactory loggerFactory;
30 private IExtendedLoggerFactory extendedLoggerFactory;
32 public LoggerResolver(ILoggerFactory loggerFactory)
34 if (loggerFactory == null) throw new ArgumentNullException("loggerFactory");
36 this.loggerFactory = loggerFactory;
39 public LoggerResolver(IExtendedLoggerFactory extendedLoggerFactory)
41 if (extendedLoggerFactory == null) throw new ArgumentNullException("extendedLoggerFactory");
43 this.extendedLoggerFactory = extendedLoggerFactory;
46 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
47 DependencyModel dependency)
49 if (CanResolve(context, parentResolver, model, dependency))
51 if (extendedLoggerFactory != null)
53 return extendedLoggerFactory.Create(model.Implementation);
55 else if (loggerFactory != null)
57 return loggerFactory.Create(model.Implementation);
59 else
61 throw new LoggerException("Unable to resolve proper LoggerFactory for Logger.");
65 return null;
68 public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
69 DependencyModel dependency)
71 return dependency.TargetType == typeof(ILogger) || dependency.TargetType == typeof(IExtendedLogger);