コード例 #1
0
        private (object Service, bool?Save) ResolveService(KeyedServiceInfo info, IServiceProvider provider, object args, bool required)
        {
            if (_service != null)
            {
                return(_service, false);
            }

            (Type KeyedType, Type Type, Func <IServiceProvider, object> Factory)typeInfo;

            if (!info.Types.TryGetValue(args, out typeInfo))
            {
                if (!required)
                {
                    return(default);
コード例 #2
0
        public object GetService(KeyedServiceInfo info, IServiceProvider provider, object args, bool required)
        {
            var result = ResolveService(info, provider, args, required);

            if (result.Service == null)
            {
                throw new Exception("Can not resolve service");
            }

            if (result.Save == true)
            {
                _service = result.Service;
            }

            return(result.Service);
        }