Exemplo n.º 1
0
        public object GetService(Type serviceType)
        {
            if (!ShouldResolveInstance(serviceType))
            {
                return(SystemActivator.CreateInstance(serviceType));
            }

            object result    = null;
            var    container = StashboxScope.GetContainer() ?? RootContainer;

            try
            {
                result = container.Resolve(serviceType);
            }
            catch (ResolutionFailedException)
            {
                // Nothing. Eat it and continue.
            }

            if (result == null)
            {
                result = _next?.GetService(serviceType);
            }

            if (result != null)
            {
                return(result);
            }

            if ((result = SystemActivator.CreateInstance(serviceType)) != null &&
                TrackUnresolvableTypes &&
                _unresolvableTypes.Count < MaxUnresolvableTypes)
            {
                _unresolvableTypes.TryAdd(serviceType, true);
            }

            return(result);
        }
Exemplo n.º 2
0
 private static void AttachEvents(HttpApplication application)
 {
     application.BeginRequest += (s, e) => StashboxScope.AddContainer();
     application.EndRequest   += (s, e) => StashboxScope.RemoveContainer();
 }
 public static IStashboxContainer GetStashboxContainer(this HttpContext httpContext) =>
 StashboxScope.GetContainer();