I am trying to inject dependencies through Spring.NET.
First I created a custom DependencyResolver:
public class SignalRSpringNetDependencyResolver : DefaultDependencyResolver { private IApplicationContext _context; public SignalRSpringNetDependencyResolver(IApplicationContext context) { _context = context; } /// <summary> /// Gets the application context. /// </summary> /// <value>The application context.</value> public IApplicationContext ApplicationContext { get { if (_context == null || _context.Name != ApplicationContextName) { if (string.IsNullOrEmpty(ApplicationContextName)) { _context = ContextRegistry.GetContext(); } else { _context = ContextRegistry.GetContext(ApplicationContextName); } } return _context; } } /// <summary> /// Gets or sets the name of the application context. /// </summary> /// <remarks> /// Defaults to using the root (default) Application Context. /// </remarks> /// <value>The name of the application context.</value> public static string ApplicationContextName { get; set; } /// <summary> /// Resolves singly registered services that support arbitrary object creation. /// </summary> /// <param name="serviceType">The type of the requested service or object.</param> /// <returns>The requested service or object.</returns> public override object GetService(Type serviceType) { System.Diagnostics.Debug.WriteLine(serviceType.FullName); if (serviceType != null && !serviceType.IsAbstract && !serviceType.IsInterface && serviceType.IsClass) { var services = ApplicationContext.GetObjectsOfType(serviceType).GetEnumerator(); services.MoveNext(); try { return services.Value; } catch (InvalidOperationException) { return null; } } else { return base.GetService(serviceType); } } /// <summary> /// Resolves multiply registered services. /// </summary> /// <param name="serviceType">The type of the requested services.</param> /// <returns>The requested services.</returns> public override IEnumerable<object> GetServices(Type serviceType) { var services = ApplicationContext.GetObjectsOfType(serviceType).Cast<object>(); services.Concat(base.GetServices(serviceType)); return services; }
Note that I avoid interfaces and abstract classes in order to get standard SignalR implementations from the DefaultDependencyResolver base
and here I assigned a converter using WebActivator:
public static void PostStart() {
However, SignalR always tries to resolve its own dependencies using the assigned Resolver i, and I get the following error:
'myhub' hub cannot be resolved.
I only need a resolver to know about other dependencies (for example, in my repository) and to support the standard implementation of SignalR services.
source share