Exemple #1
0
        FactSource GetNonGenericFactSource(
            string factId, out FactPropertiesAttribute properties)
        {
            if (mActivatedFactSources.TryGetValue(factId, out FactSource factSource))
            {
                properties = mFactSourceProperties[factId];
                return(factSource);
            }

            if (!mFactSources.TryGetValue(factId, out Type factSourceType))
            {
                throw new Exception(
                          $"There is no registered FactSource that provides '{factId}'");
            }

            FactSource instance = ActivateNonGenericSource(factSourceType);

            properties = mFactSourceProperties[factId];
            if (properties.ActivationPolicy == FactSourceActivationPolicy.JustOnce)
            {
                mActivatedFactSources.Add(factId, instance);
            }

            return(instance);
        }
Exemple #2
0
        public FactSourceContainer Register <T>() where T : FactSource
        {
            Type type = typeof(T);
            FactPropertiesAttribute attr = type.GetCustomAttributes(
                typeof(FactPropertiesAttribute),
                true).FirstOrDefault() as FactPropertiesAttribute;

            if (attr == null)
            {
                throw new Exception(
                          $"Could not find a FactPropertiesAttribute for type {type}");
            }

            if (mFactSources.ContainsKey(attr.FactId))
            {
                throw new Exception($"Duplicate FactId ${attr.FactId}");
            }

            mFactSources.Add(attr.FactId, type);
            mFactSourceProperties.Add(attr.FactId, attr);

            if (attr.ActivationPolicy == FactSourceActivationPolicy.OnEngineStartup)
            {
                FactSource factSource = ActivateSource <FactSource>(type);
                mActivatedFactSources.Add(attr.FactId, factSource);
            }

            return(this);
        }