예제 #1
0
        private object buildInstanceWithArgs(Type pluginType, Instance defaultInstance, ExplicitArguments args,
                                             string requestedName)
        {
            if (defaultInstance == null && pluginType.IsConcrete())
            {
                defaultInstance = new ConfiguredInstance(pluginType);
            }

            var basicInstance = defaultInstance as IConfiguredInstance;

            var instance = basicInstance == null
                ? defaultInstance
                : basicInstance.Override(args);

            if (instance == null)
            {
                throw new StructureMapConfigurationException("No default instance or named instance '{0}' for requested plugin type {1}", requestedName, pluginType.GetFullName());
            }

            var session = new BuildSession(_pipelineGraph, requestedName, args)
            {
                RootType = instance.ReturnedType
            };



            return(session.FindObject(pluginType, instance));
        }
예제 #2
0
 /// <summary>
 ///     Creates a new instance of the requested type using the supplied Instance.  Mostly used internally
 /// </summary>
 /// <param name="pluginType"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 public object GetInstance(Type pluginType, Instance instance)
 {
     try
     {
         var session = new BuildSession(_pipelineGraph, instance.Name);
         return(session.FindObject(pluginType, instance));
     }
     catch (StructureMapException e)
     {
         e.Push("Container.GetInstance({0}, Instance: {1})", pluginType.GetFullName(), instance.Description);
         throw;
     }
 }
예제 #3
0
        private object buildInstanceWithArgs(Type pluginType, Instance defaultInstance, ExplicitArguments args,
                                             string requestedName)
        {
            if (defaultInstance == null && pluginType.IsConcrete())
            {
                defaultInstance = new ConfiguredInstance(pluginType);
            }

            var basicInstance = defaultInstance as IConfiguredInstance;

            var instance = basicInstance == null
                ? defaultInstance
                : basicInstance.Override(args);

            var session = new BuildSession(_pipelineGraph, requestedName, args);

            return(session.FindObject(pluginType, instance));
        }
예제 #4
0
        /// <summary>
        ///     Creates a new instance of the requested type using the supplied Instance.  Mostly used internally
        /// </summary>
        /// <param name="pluginType"></param>
        /// <param name="instance"></param>
        /// <returns></returns>
        public object GetInstance(Type pluginType, Instance instance)
        {
            var session = new BuildSession(_pipelineGraph, instance.Name);

            return(session.FindObject(pluginType, instance));
        }