コード例 #1
0
        public void BuildUp(IBuilderContext context)
        {
            Guard.ArgumentNotNull(context, "context");

            if (context.Existing == null)
            {
                var currentContainer = context.NewBuildUp <IUnityContainer>();

                Type   typeToBuild = GetTypeToBuild(context.BuildKey.Type);
                string nameToBuild = context.BuildKey.Name;

                Delegate resolveMethod;

                if (IsResolvingIEnumerable(typeToBuild))
                {
                    resolveMethod = CreateResolveAllResolver(currentContainer, typeToBuild);
                }
                else
                {
                    resolveMethod = CreateResolver(currentContainer, typeToBuild, nameToBuild);
                }

                context.Existing = resolveMethod;

                DynamicMethodConstructorStrategy.SetPerBuildSingleton(context);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates an instance of this build plan's type, or fills
        /// in the existing type if passed in.
        /// </summary>
        /// <param name="context">Context used to build up the object.</param>
        public void BuildUp(IBuilderContext context)
        {
            if (context.Existing == null)
            {
                var currentContainer = context.NewBuildUp <IUnityContainer>();
                context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name);

                DynamicMethodConstructorStrategy.SetPerBuildSingleton(context);
            }
        }
        private static void BuildResolveAllLazy <T>(IBuilderContext context)
        {
            if (context.Existing == null)
            {
                var container = context.NewBuildUp <IUnityContainer>();
                context.Existing = new Lazy <IEnumerable <T> >(() => container.ResolveAll <T>());
            }

            // match the behavior of DynamicMethodConstructorStrategy
            DynamicMethodConstructorStrategy.SetPerBuildSingleton(context);
        }
コード例 #4
0
        public void BuildUp(IBuilderContext context)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(context, "context");

            if (context.Existing == null)
            {
                var currentContainer = context.NewBuildUp <IUnityContainer>();
                context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name);

                DynamicMethodConstructorStrategy.SetPerBuildSingleton(context);
            }
        }