Exemplo n.º 1
0
 public void Build(CatBuilderContext builderContext)
 {
     allBuilders = new Stack<ICatBuilder>(builders.Reverse());
     effectiveBuilders.Clear();
     PreBuildCore(builderContext);
     PostBuildCore(builderContext);
 }
Exemplo n.º 2
0
        public void PostBuild(CatBuilderContext builderContext, Action<CatBuilderContext> delegateToNextBuilder)
        {
            CatRegistration registration;
            if (builderContext.IsCompleted && builderContext.Cat.TryGetRegistration(builderContext.ServiceType, builderContext.RegistrationName, out registration))
            {
                registration.LifetimeManager.SetValue(builderContext.Service);
            }

            delegateToNextBuilder(builderContext);
        }
Exemplo n.º 3
0
 private void PostBuildCore(CatBuilderContext builderContext)
 {
     if (effectiveBuilders.Any())
     {
         ICatBuilder builder = effectiveBuilders.Pop();
         builder.PostBuild(builderContext, context =>
         {
             PostBuildCore(builderContext);
         });
     }
 }
Exemplo n.º 4
0
        public void PreBuild(CatBuilderContext builderContext, Action<CatBuilderContext> delegateToNextBuilder)
        {
            if(null != builderContext.Registration)
            {
                object service;
                if (builderContext.Registration.LifetimeManager.TryGetValue(out service))
                {
                    builderContext.Service = service;
                    builderContext.IsCompleted = true;
                }
            }

            delegateToNextBuilder(builderContext);
        }
Exemplo n.º 5
0
 private void PreBuildCore(CatBuilderContext builderContext)
 {
     if (!builderContext.IsCompleted && allBuilders.Any() && null == builderContext.Exception)
     {
         ICatBuilder builder= allBuilders.Pop();
         builder.PreBuild(builderContext, context =>
         {
             if (!builderContext.IsCompleted)
             {
                 PreBuildCore(builderContext);
             }
         });
         effectiveBuilders.Push(builder);
     }
 }
Exemplo n.º 6
0
        public void PostBuild(CatBuilderContext context, Action<CatBuilderContext> delegateToNextBuilder)
        {
            if (null != context.Service)
            {
                foreach (MethodInfo method in this.GetInjectionMethods(context.Service.GetType()))
                {
                    object[] arguments = method.GetParameters().Select(p => context.Cat.GetService(p.ParameterType)).ToArray();
                    method.Invoke(context.Service, arguments);
                }

                foreach (PropertyInfo property in this.GetInjectionProperties(context.Service.GetType()))
                {
                    property.SetValue(context.Service, context.Cat.GetService(property.PropertyType));
                }
            }
        }
Exemplo n.º 7
0
        public void PreBuild(CatBuilderContext builderContext, Action<CatBuilderContext> delegateToNextBuilder)
        {
            Type type = null;
            CatRegistration registration;
            if (builderContext.Cat.TryGetRegistration(builderContext.ServiceType, builderContext.RegistrationName, out registration))
            {
                type = registration.To;              
            }

            if (null == type)
            {
                type = builderContext.ServiceType;
            }

            ConstructorInfo constructor = this.GetConstructor(type);
            object[] arguments = constructor.GetParameters().Select(p => builderContext.Cat.GetService(p.ParameterType)).ToArray();
            builderContext.Service = constructor.Invoke(arguments);
            builderContext.IsCompleted = builderContext.Service != null;
        }
Exemplo n.º 8
0
        public object GetService(Type type, string name)
        {
            this.Initialize();
            CatBuilderContext context = new CatBuilderContext(this, type, name);
            builderPipeline.Build(context);
            if (null != context.Exception)
            {
                throw context.Exception;
            }

            if (context.IsCompleted)
            {
                return context.Service;
            }
            else if (null != this.Parent)
            {
                return this.Parent.GetService(type);
            }
            return null;
        }
Exemplo n.º 9
0
 public void PreBuild(CatBuilderContext context, Action<CatBuilderContext> delegateToNextBuilder)
 {
     delegateToNextBuilder(context);
 }
Exemplo n.º 10
0
 public void PostBuild(CatBuilderContext builderContext, Action<CatBuilderContext> delegateToNextBuilder)
 {
    
 }