public static IRegister GetRegistration(TokenStore store, IFilterToken groupToken, int priority)
        {
            var inner          = new InnerRegistration(store, groupToken, priority);
            var innerHighLevel = new InnerHighLevelRegistration(store, groupToken, priority);

            return(new Registration(store, inner, innerHighLevel));
        }
Example #2
0
 public Declarator(TokenStore store, IToken <T> token, IProvider provider, IFilterToken groupToken, int priority)
 {
     this.store      = store;
     this.token      = token;
     this.provider   = provider;
     this.groupToken = groupToken;
     this.priority   = priority;
 }
Example #3
0
 public GroupProvider(IEnumerable<IDependency> dependencies,
     IFilterGroup group,
     TokenStore store,
     IDiagInfo diagInfo)
 {
     Dependencies = dependencies;
     DiagInfo = diagInfo;
     this.group = group;
     this.store = store;
 }
        public static IFor <T1> GetRegistration1 <T1>(TokenStore store,
                                                      IDependency <T1> dependency,
                                                      IFilterToken groupToken,
                                                      int priority)
        {
            var inner          = new InnerRegistration1 <T1>(store, dependency, groupToken, priority);
            var innerHighLevel = new InnerHighLevelRegistration(store, groupToken, priority, dependency);

            return(new Registration1 <T1>(store, inner, innerHighLevel));
        }
Example #5
0
        public static IHaveToken <T> GetHaveToken <T>(this TokenStore store, IDiagInfo diagInfo, string name)
        {
            var token = store.GetToken <T>(name);

            if (token != null)
            {
                return(new HaveToken <T>(token));
            }

            return(new LazyHaveToken <T>(() => store.GetToken <T>(name), name, diagInfo));
        }
Example #6
0
        public static void SaveToken <T>(this TokenStore store, IDiagInfo diagInfo, string name, IToken <T> token)
        {
            if (store.GetToken <T>(name) != null)
            {
                throw new RegistrationException($"Definition for {token} is already registered", diagInfo);
            }

            if (token == null)
            {
                throw new RegistrationException($"Attempted to register null as token for {typeof(T).Name} \"{name}\"", diagInfo);
            }

            store.Tokens.Set(token, name);
            token.Name = name;
        }
        public static void DetectRegistrationsLoop(TokenStore store)
        {
            var vertices = store.Providers.Select(x => new ProviderVertex { Provider = x.Value, Token = x.Key })
                                .ToDictionary(x => x.Token);
            var rootVertex = new ProviderVertex { Token = store.RootToken };
            vertices.Add(store.RootToken, rootVertex);
            foreach (var vertex in vertices.Values.Where(x => x.Token != store.RootToken))
            {
                foreach (var dependency in vertex.Provider.Dependencies)
                {
                    vertices[dependency.Token].Dependencies.Add(vertex);
                }
            }

            foreach(var loop in new TarjanLoopDetection<ProviderVertex>().DetectLoop(vertices.Values.ToArray()).Where(x=>x.Count > 1))
            {
                var types = string.Join(",", loop.Select(x => x.Token));
                var tuples = loop.Select(x => new Tuple<IToken, IDiagInfo>(x.Token, x.Provider.DiagInfo)).ToList();
                throw new DetailedRegistrationException("Following types declare a dependency loop" + types, tuples);
            }
        }
Example #8
0
 public Inversion(TokenStore store)
 {
     this.store = store;
 }
Example #9
0
 public static IToken <T> GetToken <T>(this TokenStore store, string name)
 => store.Tokens.Get <IToken <T> >(name);
Example #10
0
 public static void RegisterProvider(this TokenStore store, IProvider provider, IToken token)
 {
     store.Providers.Add(token, provider);
 }
Example #11
0
 public static void RegisterCvFilter(this TokenStore store, FilterRegistration filter, IFilterToken token)
 {
     store.RegisterFilter(filter);
     store.CvFilters.Add(token);
 }
Example #12
0
 public static void RegisterFilter(this TokenStore store, FilterRegistration filter)
 {
     store.FilterRegistrations.Add(filter);
 }