34 lines
981 B
C#
34 lines
981 B
C#
|
namespace Nautilus.Web.Impulse.DependencyResolution
|
||
|
{
|
||
|
using StructureMap;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Web.Mvc;
|
||
|
|
||
|
public class SmDependencyResolver : IDependencyResolver {
|
||
|
|
||
|
private readonly IContainer _container;
|
||
|
|
||
|
public SmDependencyResolver(IContainer container) {
|
||
|
_container = container;
|
||
|
}
|
||
|
|
||
|
public object GetService(Type serviceType) {
|
||
|
if (serviceType == null) return null;
|
||
|
try {
|
||
|
return serviceType.IsAbstract || serviceType.IsInterface
|
||
|
? _container.TryGetInstance(serviceType)
|
||
|
: _container.GetInstance(serviceType);
|
||
|
}
|
||
|
catch {
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public IEnumerable<object> GetServices(Type serviceType) {
|
||
|
return _container.GetAllInstances(serviceType).Cast<object>();
|
||
|
}
|
||
|
}
|
||
|
}
|