public void Process(Type type, global::StructureMap.Configuration.DSL.Registry registry) { if (type.IsAbstract) { return; } if (type.IsInterface) { return; } var originalInterface = type.GetInterfaces().FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == _baseInterface); if (originalInterface == null) return; Type[] wrappedTypes = originalInterface.GetGenericArguments(); // Create the created type Type implementationType = _baseInterface.MakeGenericType(wrappedTypes); // And specify what we're going to use registry.For(implementationType).Use(type); }
/// <summary> /// Registers found Rebus handler types in the container /// </summary> public void ScanTypes(TypeSet types, global::StructureMap.Registry registry) { var messageHandlers = types.FindTypes(TypeClassification.Concretes) .Where(t => t.CanBeCastTo(typeof(IHandleMessages))); foreach (var handlerType in messageHandlers) { var handlerInterfaces = handlerType.GetInterfaces().Where(IsHandler).ToList(); foreach (var handlerInterface in handlerInterfaces) { registry .For(handlerInterface) .Use(handlerType) .LifecycleIs<UniquePerRequestLifecycle>(); } } }