blob: 0eedd3854956b513d8a102691e26cbf18878a452 (
plain)
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
|
using System.Collections.Generic;
using System.Linq;
namespace System.Web.Mvc
{
internal class MultiServiceResolver<TService> : IResolver<IEnumerable<TService>>
where TService : class
{
private Lazy<IEnumerable<TService>> _itemsFromService;
private Func<IEnumerable<TService>> _itemsThunk;
private Func<IDependencyResolver> _resolverThunk;
public MultiServiceResolver(Func<IEnumerable<TService>> itemsThunk)
{
if (itemsThunk == null)
{
throw new ArgumentNullException("itemsThunk");
}
_itemsThunk = itemsThunk;
_resolverThunk = () => DependencyResolver.Current;
_itemsFromService = new Lazy<IEnumerable<TService>>(() => _resolverThunk().GetServices<TService>());
}
internal MultiServiceResolver(Func<IEnumerable<TService>> itemsThunk, IDependencyResolver resolver)
: this(itemsThunk)
{
if (resolver != null)
{
_resolverThunk = () => resolver;
}
}
public IEnumerable<TService> Current
{
get { return _itemsFromService.Value.Concat(_itemsThunk()); }
}
}
}
|