/// <summary> /// Resolve an instance based on context, binding and service /// </summary> /// <param name="context"><see cref="IComponentContext"/> to resolve from</param> /// <param name="binding"><see cref="Binding"/> to resolve</param> /// <param name="service"><see cref="Type">Service type</see> asked for</param> /// <returns>Resolved instance</returns> public object Resolve(IComponentContext context, Binding binding, Type service) { lock (_instancesPerKey) { var key = _tenantKeyCreator.GetKeyFor( binding, service); if (_instancesPerKey.ContainsKey(key)) return _instancesPerKey[key]; object instance = null; switch (binding.Strategy) { case Strategies.Type type: instance = _activator.CreateInstanceFor(context, binding.Service, type.Target); break; case Strategies.Constant constant: instance = constant.Target; break; case Strategies.Callback callback: instance = callback.Target(); break; case Strategies.TypeCallback typeCallback: var typeFromCallback = typeCallback.Target(); instance = _activator.CreateInstanceFor(context, binding.Service, typeFromCallback); break; } _instancesPerKey[key] = instance; return instance; } }