예제 #1
0
        /// <inheritdoc />
        public object GetService([NotNull] Type serviceType)
        {
            if (ResolvedDependencies.TryGetValue(serviceType, out var foundService))
            {
                return(foundService);
            }

            var thisType       = typeof(IntersectServiceDependencyResolver);
            var definitionType = serviceType;

            if (serviceType.IsAbstract || serviceType.IsInterface)
            {
                definitionType = Assembly.GetAssembly(thisType)
                                 ?.DefinedTypes
                                 ?.Where(typeInfo => typeInfo?.Namespace?.StartsWith(thisType.Namespace ?? "") ?? false)
                                 .FirstOrDefault(typeInfo => serviceType.IsAssignableFrom(typeInfo.AsType()));
            }

            var constructor =
                definitionType?.GetConstructor(new[] { typeof(ApiConfiguration), typeof(HttpConfiguration) });

            var constructedService = constructor?.Invoke(new object[] { ApiConfiguration, HttpConfiguration });

            ResolvedDependencies[serviceType] = constructedService;

            return(constructedService);
        }
예제 #2
0
 /// <inheritdoc />
 public void Dispose()
 {
     ResolvedDependencies.Clear();
 }