Exemple #1
0
        private static T LocateInstance(RealObjectFactory <T> factory, string version, string[] filters, bool throwOnError)
        {
            T instance = factory.GetService(version, filters);

            if (instance == null && throwOnError)
            {
                StringBuilder sb = new StringBuilder();
                if (filters != null && filters.Length > 0)
                {
                    sb.Append(" with the filter : {");
                    foreach (var f in filters)
                    {
                        sb.Append(" \"" + f + "\",");
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.Append(" }");
                }
                throw new ApplicationException("Can't load the implementation instance of type'" + typeof(T).AssemblyQualifiedName + "' for version '" + version + "'" + sb.ToString() + ".");
            }
            return(instance);
        }
Exemple #2
0
        public static T NewInstance(string version, string[] filters, bool throwOnError)
        {
            RealObjectFactory <T> factory;

            if (throwOnError)
            {
                factory = new RealObjectFactory <T>();
            }
            else
            {
                try
                {
                    factory = new RealObjectFactory <T>();
                }
                catch
                {
                    return(null);
                }
            }
            return(LocateInstance(factory, version, filters, throwOnError));
        }