public void ChangeType_ProvidesKeyedServiceWithNewTypeAndSameKey() { var newType = typeof(string); var key = new object(); var service = new KeyedService(key, typeof(object)); var changedService = service.ChangeType(newType); Assert.AreEqual(new KeyedService(key, newType), changedService); }
public static ResolvedParameter ForKeyed <TService>(object serviceKey) { if (serviceKey == null) { throw new ArgumentNullException("serviceKey"); } KeyedService ks = new KeyedService(serviceKey, typeof(TService)); return(new ResolvedParameter((pi, c) => (pi.ParameterType == typeof(TService)) && c.IsRegisteredService(ks), (pi, c) => c.ResolveService(ks))); }
public override bool Equals(object obj) { KeyedService service = obj as KeyedService; if (service == null) { return(false); } return(this.ServiceKey.Equals(service.ServiceKey) && this.ServiceType.IsCompatibleWith(service.ServiceType)); }
public void RespectsExplicitInterchangeServices() { var builder = new ContainerBuilder(); var catalog = new TypeCatalog(typeof(HasMultipleExports)); var interchangeService1 = new TypedService(typeof(HasMultipleExportsBase)); var interchangeService2 = new KeyedService("b", typeof(HasMultipleExports)); var nonInterchangeService1 = new TypedService(typeof(HasMultipleExports)); var nonInterchangeService2 = new KeyedService("a", typeof(HasMultipleExports)); builder.RegisterComposablePartCatalog(catalog, interchangeService1, interchangeService2); var container = builder.Build(); Assert.IsTrue(container.IsRegisteredService(interchangeService1)); Assert.IsTrue(container.IsRegisteredService(interchangeService2)); Assert.IsFalse(container.IsRegisteredService(nonInterchangeService1)); Assert.IsFalse(container.IsRegisteredService(nonInterchangeService2)); }
public override IController CreateController(RequestContext requestContext, string controllerName) { var routeData = requestContext.RouteData; // Determine the area name for the request, and fall back to stock orchard controllers var areaName = GetAreaName(routeData); // Service name pattern matches the identification strategy var serviceKey = (areaName + "/" + controllerName).ToLowerInvariant(); // Now that the request container is known - try to resolve the controller object controller; var service = new KeyedService(serviceKey, typeof(IController)); // Locate the container this route is bound against var container = GetRequestContainer(routeData); if (container != null && container.TryResolve(service, out controller)) { return (IController)controller; } return base.CreateController(requestContext, controllerName); }
/// <summary> /// The get controller session behavior. /// </summary> /// <param name="requestContext"> /// The request context. /// </param> /// <param name="controllerName"> /// The controller name. /// </param> public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName) { if (requestContext == null) { throw new ArgumentNullException("requestContext"); } if (string.IsNullOrEmpty(controllerName)) { throw new ArgumentNullException("controllerName"); } // Check controller name exist in cache or not var keyedService = new KeyedService(controllerName.ToLowerInvariant(), typeof(IController)); IComponentRegistration registry; this.container.ComponentRegistry.TryGetRegistration(keyedService, out registry); if (registry != null) { return this.GetControllerSessionBehavior(requestContext, registry.Activator.LimitType); } return this.defaultFactory.GetControllerSessionBehavior(requestContext, controllerName); }
public void SetUp() { _modelMapper = new ModelMapper(); TypeModel unused; _modelMapper.GetOrAddTypeModel(typeof(string), out unused); _service = new KeyedService(new object(), typeof(string)); _mapped = _modelMapper.GetServiceModel(_service); }