Пример #1
0
 /// <summary>
 /// Recupera il nome completo del tipo in base al nome parziale
 /// </summary>
 /// <param name="typename">come parziale del tipo</param>
 /// <returns></returns>
 protected static string GetCompleteNameOf(string typename)
 {
     for (var i = 0; i < Instance.Kernel.GraphNodes.Length; i++)
     {
         Castle.Core.ComponentModel component = (Castle.Core.ComponentModel)Instance.Kernel.GraphNodes[i];
         if (component.ComponentName.Name.Contains(typename))
         {
             return(component.ComponentName.Name);
         }
     }
     return(string.Empty);
 }
        public object Resolve(
            Castle.MicroKernel.Context.CreationContext context,
            ISubDependencyResolver contextHandlerResolver,
            Castle.Core.ComponentModel model,
            Castle.Core.DependencyModel dependency)
        {
            var configuration = ConfigurationServiceClient.Instance.GetSetting(dependency.DependencyKey);

            return(new StringConfiguration()
            {
                Value = configuration,
            });
        }
Пример #3
0
        private void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
        {
            var isView = typeof(IView).IsAssignableFrom(model.Implementation);

            if (!isView)
            {
                return;
            }

            if (model.CustomComponentActivator == null)
            {
                model.CustomComponentActivator = typeof(ViewComponentActivator);
            }
        }
Пример #4
0
        void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
        {
            var isView = model.Services.Any(s => typeof(IView).IsAssignableFrom(s));

            if (!isView)
            {
                return;
            }

            if (model.CustomComponentActivator == null)
            {
                model.CustomComponentActivator = typeof(WPFWindowActivator);
            }
        }
Пример #5
0
 /// <inheritdoc />
 public Type[] GetGenericArguments(Castle.Core.ComponentModel model, CreationContext context)
 {
     Type[] arguments;
     if (context.RequestedType.GenericTypeArguments.Length > 0)
     {
         return(context.RequestedType.GenericTypeArguments);
     }
     else if ((arguments = model.Implementation.GetGenericArguments()).Length > 0)
     {
         return(arguments.SelectMany(argument =>
                                     argument.GetGenericParameterConstraints().SelectMany(constrain =>
                                                                                          _container.ResolveAllTypes(constrain))).ToArray());
     }
     else
     {
         return(new Type[] { typeof(object) });
     }
 }
Пример #6
0
        private void ComponentCreated(Castle.Core.ComponentModel model, object instance)
        {
            if (!model.ExtendedProperties.Contains(typeof(EventBrokerFacility)))
            {
                return;
            }
            var dict = (Dictionary <string, object>)model.ExtendedProperties [typeof(EventBrokerFacility)];
            var pubs = (List <PubStub>)dict ["pub"];
            var subs = (List <SubStub>)dict ["sub"];

            foreach (var pub in pubs)
            {
                _eventBroker.AddPublisher(pub.Topics, instance, pub.Event);
            }
            foreach (var sub in subs)
            {
                _eventBroker.AddSubscriber(sub.Topic, instance, sub.Method);
            }
        }
Пример #7
0
 public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
 {
     return(NLog.LogManager.GetLogger(model.Implementation.FullName));
 }
Пример #8
0
 public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
 {
     return(dependency.TargetType == typeof(ILogger));
 }
Пример #9
0
 public object Resolve(Castle.MicroKernel.Context.CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, Castle.Core.DependencyModel dependency)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 static void Kernel_DependencyResolving(Castle.Core.ComponentModel client, Castle.Core.DependencyModel model, object dependency)
 {
     Logger.DebugFormat("IOC Container: Kernel dependency resolving. Client: {0}, Dependency key: {1}, dependency: {2}", client.Name, model.DependencyKey, dependency);
 }
Пример #11
0
 private void Kernel_DependencyResolving(Castle.Core.ComponentModel client, Castle.Core.DependencyModel model,
                                         object dependency)
 {
     _logger.DebugFormat("~ Resolving dependency '{0}' for component '{1}'.", model.TargetType.Name, client.Service.Name);
 }
    public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
    {
        if ((
                from constructor in model.Constructors
                from dependencyModel in constructor.Dependencies
                where dependencyModel == dependency

                from parameterInfo in constructor.Constructor.GetParameters()
                select parameterInfo).Any(parameterInfo => parameterInfo.Name == dependency.DependencyKey))
        {
            var converter = (IConversionManager)kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);
            return(converter.PerformConversion(ConfigurationManager.AppSettings[dependency.DependencyKey], dependency.TargetType));
        }
        return(null);
    }
    public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
    {
        return((
                   from constructor in model.Constructors
                   from dependencyModel in constructor.Dependencies
                   where dependencyModel == dependency

                   from parameterInfo in constructor.Constructor.GetParameters()
                   where parameterInfo.Name == dependency.DependencyKey
                   select(Attribute.GetCustomAttribute(parameterInfo, typeof(AppSettingsAttribute)) != null)
                   ).FirstOrDefault());
    }
Пример #14
0
 public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
 {
     return(NLog.LogManager.GetLogger(GetType()));
 }
Пример #15
0
 private void Kernel_ComponentCreated(Castle.Core.ComponentModel model, object instance)
 {
     _logger.DebugFormat("*** Created component '{0}'.", model.Service.Name);
 }
Пример #16
0
 /// <summary>
 /// log when a new component is create in the container
 /// </summary>
 /// <param name="model"></param>
 /// <param name="instance"></param>
 void Kernel_ComponentCreated(Castle.Core.ComponentModel model, object instance)
 {
     Logger.Debug("Component created: " + model.Name);
 }
Пример #17
0
 /// <summary>
 /// log when a component resolved by the contained is destroyed
 /// </summary>
 /// <param name="model"></param>
 /// <param name="instance"></param>
 void Kernel_ComponentDestroyed(Castle.Core.ComponentModel model, object instance)
 {
     Logger.Debug("Component destroyed: " + model.Name);
 }
 public DXViewModelActivator(Castle.Core.ComponentModel model, Castle.MicroKernel.IKernelInternal kernel, Castle.MicroKernel.ComponentInstanceDelegate onCreation, Castle.MicroKernel.ComponentInstanceDelegate onDestruction)
     : base(model, kernel, onCreation, onDestruction)
 {
     Model.Implementation = TryGetPOCOType(Model.Implementation);
 }
Пример #19
0
 public BuildUpComponentActivator(Castle.Core.ComponentModel model, IKernel kernel, ComponentInstanceDelegate onCreation, ComponentInstanceDelegate onDestruction)
     : base(model, kernel, onCreation, onDestruction)
 {
 }
Пример #20
0
 private void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
 {
     _logger.DebugFormat(": Created ComponentModel '{0}' for service '{1}' implemented by '{2}'.", model.Name,
                         model.Service.Name, model.Implementation.FullName);
 }