示例#1
0
        protected static TInput GetOrRegister <TInput>(IEnumerable <Type> interfaceTypes)
        {
            lock (_lock)
            {
                if (frameworkContainer.IsRegisted(typeof(TInput)))
                {
                    return(frameworkContainer.Resolve <TInput>());
                }

                Type type;
                if (typeof(TInput).IsInterface)
                {
                    interfaceTypes = interfaceTypes.Concat(new[] { typeof(ISPResult) });
                    type           = DynamicObject.InterfaceImplementationType(interfaceTypes.ToArray());
                    frameworkContainer.RegisterType(typeof(TInput), type, LifetimeFlag.PerCall);
                }
                else
                {
                    type = DynamicObject.InterfaceImplementationType(new[] { typeof(ISPResult) }, typeof(TInput), null);
                    frameworkContainer.RegisterType(typeof(TInput), type, LifetimeFlag.PerCall);
                }

                if (typeof(TInput) != type)
                {
                    //RegistorTypeDescriptor(type, typeof(TInput));
                }

                return(frameworkContainer.Resolve <TInput>());
            }
        }
示例#2
0
        public static T New <T>(this T type, IFrameworkContainer container)
        {
            var resolve = container.Resolve <T>();

            if (resolve == null)
            {
                container.RegisterType <T>();
            }

            return(container.Resolve <T>());
        }