本文整理汇总了C#中IKernel.HasComponent方法的典型用法代码示例。如果您正苦于以下问题:C# IKernel.HasComponent方法的具体用法?C# IKernel.HasComponent怎么用?C# IKernel.HasComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKernel
的用法示例。
在下文中一共展示了IKernel.HasComponent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(IKernel kernel, Castle.Core.Configuration.IConfiguration facilityConfig)
{
Kernel = kernel;
if (Kernel.HasComponent(typeof(ViewAccessor<>)) == false)
Kernel.Register(Component.For(typeof(ViewAccessor<>)).LifeStyle.Singleton);
if (Kernel.HasComponent(typeof(ControllerAccessor<,>)) == false)
Kernel.Register(Component.For(typeof(ControllerAccessor<,>)).LifeStyle.Singleton);
if (Kernel.HasComponent<IActionInvoker>() == false)
Kernel.Register(Component.For<IActionInvoker>().ImplementedBy<DefaultActionInvoker>().LifeStyle.Singleton);
if (Kernel.HasComponent<ICommandProvider>() == false)
Kernel.Register(Component.For<ICommandProvider>().ImplementedBy<DefaultCommandProvider>().LifeStyle.Singleton);
if (Kernel.HasComponent<IControllerAdapter>() == false)
Kernel.Register(Component.For<IControllerAdapter>().ImplementedBy<DefaultControllerAdapter>().LifeStyle.Singleton);
if (Kernel.HasComponent<IControllerLifecycleManager>() == false)
Kernel.Register(Component.For<IControllerLifecycleManager>().ImplementedBy<MicroKernelControllerLifecycleManager>().LifeStyle.Singleton);
if (Kernel.HasComponent<IAutoRegistration>() == false)
Kernel.Register(Component.For<IAutoRegistration>().ImplementedBy<MicroKernelAutoRegistration>().LifeStyle.Singleton);
Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated);
Kernel.ComponentRegistered += new ComponentDataDelegate(Kernel_ComponentRegistered);
Kernel.ComponentCreated += new ComponentInstanceDelegate(Kernel_ComponentCreated);
}
示例2: Resolve
/// <summary>
/// Resolves the component(s) from given kernel.
/// </summary>
/// <param name = "kernel"></param>
/// <returns>Resolved component(s).</returns>
public virtual object Resolve(IKernel kernel)
{
if (string.IsNullOrEmpty(ComponentName) == false && kernel.HasComponent(ComponentName))
{
if (ComponentType == null)
{
return kernel.Resolve(ComponentName, AdditionalArguments);
}
return kernel.Resolve(ComponentName, ComponentType, AdditionalArguments);
}
return kernel.Resolve(ComponentType, AdditionalArguments);
}
示例3: Init
public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
{
base.Init(componentActivator, kernel, model);
// check ILoggerFactory is registered (logging is enabled)
if (kernel.HasComponent(typeof(ILoggerFactory)))
{
// get logger factory instance
ILoggerFactory loggerFactory = kernel.Resolve<ILoggerFactory>();
// create logger
_Logger = loggerFactory.Create(GetType());
}
else
_Logger = NullLogger.Instance;
}
示例4: ProcessModel
public override void ProcessModel(IKernel kernel, ComponentModel model)
{
if (model.Service is IBehaviorStore)
{
foreach (var node in kernel.GraphNodes.OfType<ComponentModel>())
{
SetProxyInformation(node, kernel.Resolve<IBehaviorConfigurator>());
}
return;
}
if (!kernel.HasComponent(typeof (IBehaviorStore))) return;
var behaviorToProxyResolver = kernel.Resolve<IBehaviorConfigurator>();
//Get the proxy info
SetProxyInformation(model, behaviorToProxyResolver);
}
示例5: InjectProperties
public static void InjectProperties(IKernel kernel, object target)
{
var type = target.GetType();
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (property.CanWrite && kernel.HasComponent(property.PropertyType))
{
var value = kernel.Resolve(property.PropertyType);
try
{
property.SetValue(target, value, null);
}
catch (Exception ex)
{
var message = string.Format("Error setting property {0} on type {1}, See inner exception for more information.", property.Name, type.FullName);
throw new ComponentActivatorException(message, ex, null);
}
}
}
}
示例6: foreach
void IRegistration.Register(IKernel kernel)
{
foreach (IWcfClientModel channel in channels)
{
var registration = Component.For(channel.Contract);
registration.DependsOn(Property.ForKey("channel").Eq(channel));
if (configurer != null)
{
configurer(registration);
}
if (String.IsNullOrEmpty(registration.Name))
{
registration.Named(Guid.NewGuid().ToString());
}
if (!kernel.HasComponent(registration.Name))
{
kernel.Register(registration);
}
}
}
示例7: Resolve
public override object Resolve(IKernel kernel)
{
return kernel.HasComponent(ComponentName) ? base.Resolve(kernel) : new DefaultModelBinder();
}