forked from hibernating-rhinos/rhino-esb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCastleServiceLocator.cs
51 lines (43 loc) · 1.34 KB
/
CastleServiceLocator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using Castle.MicroKernel.Context;
using Castle.Windsor;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
namespace Rhino.ServiceBus.Castle
{
public class CastleServiceLocator : IServiceLocator
{
private readonly IWindsorContainer container;
public CastleServiceLocator(IWindsorContainer container)
{
this.container = container;
}
public T Resolve<T>()
{
return container.Resolve<T>();
}
public object Resolve(Type type)
{
return container.Resolve(type);
}
public bool CanResolve(Type type)
{
return container.Kernel.HasComponent(type);
}
public IEnumerable<T> ResolveAll<T>()
{
return container.ResolveAll<T>();
}
public IEnumerable<IHandler> GetAllHandlersFor(Type type)
{
return (from h in container.Kernel.GetAssignableHandlers(type)
select (IHandler)new DefaultHandler(null, h.ComponentModel.Implementation, () => h.Resolve(new CreationContext(h, container.Kernel.ReleasePolicy, type, null, null, null))));
}
public void Release(object item)
{
container.Kernel.ReleaseComponent(item);
}
}
}