本文整理汇总了C#中DefaultKernel.AddSubSystem方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel.AddSubSystem方法的具体用法?C# DefaultKernel.AddSubSystem怎么用?C# DefaultKernel.AddSubSystem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DefaultKernel
的用法示例。
在下文中一共展示了DefaultKernel.AddSubSystem方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComponentGraph
public void ComponentGraph()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
GraphNode[] nodes = kernel.GraphNodes;
Assert.IsNotNull(nodes);
Assert.AreEqual(2, nodes.Length);
}
示例2: EmptyDelegateReturnsFirstTypeLoaded
public void EmptyDelegateReturnsFirstTypeLoaded()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());
kernel.AddComponent("1.common", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("2.common", typeof(ICommon), typeof(CommonImpl2));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
}
示例3: GetAssignableHandlers
public void GetAssignableHandlers()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
IHandler[] handlers = kernel.GetAssignableHandlers(typeof(ICommon));
Assert.IsNotNull(handlers);
Assert.AreEqual(2, handlers.Length);
}
示例4: ServiceLookup
public void ServiceLookup()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
}
示例5: ReturnsFirstMatchingType
public void ReturnsFirstMatchingType()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey,
new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("1"); }));
kernel.AddComponent("1.common", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("11.common", typeof(ICommon), typeof(CommonImpl2));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
}
示例6: ReturnsFirstTypeWhenNotFound
public void ReturnsFirstTypeWhenNotFound()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey,
new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("3"); }));
kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("1.common"));
kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl2)).Named("2.common"));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
}
示例7: ReturnsCorrectType
public void ReturnsCorrectType()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey,
new KeySearchNamingSubSystem(
delegate(string key) { return key.StartsWith("castlestronghold.com"); }));
kernel.AddComponent("castleproject.org.common", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("castlestronghold.com.common", typeof(ICommon), typeof(CommonImpl2));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl2), common.GetType());
}
示例8: MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService
public void MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService()
{
var threadCount = 1000;
var list = new List<Exception>();
var locker = new object();
var rand = new Random();
var waitEvent = new ManualResetEvent(false);
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem(delegate { return false; }));
kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("common"));
WaitCallback resolveThread = delegate
{
waitEvent.WaitOne();
while (threadCount > 0 && list.Count == 0)
{
try
{
kernel.Resolve<ICommon>();
}
catch (Exception e)
{
lock (locker)
{
list.Add(e);
}
}
}
};
ThreadPool.QueueUserWorkItem(resolveThread);
WaitCallback removeThread = delegate
{
waitEvent.WaitOne();
kernel.RemoveComponent(threadCount + ".common");
Interlocked.Decrement(ref threadCount);
};
for (var i = 0; i < threadCount; i++)
{
kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named(i + ".common"));
ThreadPool.QueueUserWorkItem(removeThread);
}
waitEvent.Set();
while (threadCount > 0 && list.Count == 0)
{
Thread.Sleep(15);
}
if (list.Count > 0)
{
throw list[0];
}
}
示例9: ComponentUnregistersProperly
public void ComponentUnregistersProperly()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey,
new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("2"); }));
kernel.AddComponent("1.common", typeof(ICommon), typeof(CommonImpl1));
kernel.AddComponent("2.common", typeof(ICommon), typeof(CommonImpl2));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl2), common.GetType());
kernel.RemoveComponent("2.common");
common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
kernel.RemoveComponent("1.common");
Assert.AreEqual(0, kernel.GetHandlers(typeof(ICommon)).Length);
}
示例10: MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService
public void MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService()
{
int threadCount = 1000;
ArrayList list = ArrayList.Synchronized(new ArrayList());
Random rand = new Random();
ManualResetEvent waitEvent = new ManualResetEvent(false);
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem(delegate { return false; }));
kernel.AddComponent("common", typeof(ICommon), typeof(CommonImpl1));
WaitCallback resolveThread = delegate
{
waitEvent.WaitOne();
while(threadCount > 0 && list.Count == 0)
{
try
{
ICommon common = kernel[typeof(ICommon)] as ICommon;
}
catch(Exception e)
{
list.Add(e);
}
}
};
ThreadPool.QueueUserWorkItem(resolveThread);
WaitCallback removeThread = delegate
{
waitEvent.WaitOne();
kernel.RemoveComponent(threadCount + ".common");
Interlocked.Decrement(ref threadCount);
};
for(int i = 0; i < threadCount; i++)
{
kernel.AddComponent(i + ".common", typeof(ICommon), typeof(CommonImpl1));
ThreadPool.QueueUserWorkItem(removeThread);
}
waitEvent.Set();
while(threadCount > 0 && list.Count == 0)
{
Thread.Sleep(15);
}
if (list.Count > 0)
{
throw (Exception) list[0];
}
}
示例11: MultiThreadedAddResolve
public void MultiThreadedAddResolve()
{
int threadCount = 100;
ArrayList list = ArrayList.Synchronized(new ArrayList());
Random rand = new Random();
ManualResetEvent waitEvent = new ManualResetEvent(false);
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());
kernel.AddComponent("common", typeof(ICommon), typeof(CommonImpl1));
WaitCallback resolveThread = delegate
{
waitEvent.WaitOne();
while(threadCount > 0 && list.Count == 0)
{
try
{
ICommon common = kernel[typeof(ICommon)] as ICommon;
}
catch(Exception e)
{
list.Add(e.ToString());
}
}
};
ThreadPool.QueueUserWorkItem(resolveThread);
WaitCallback addThread = delegate
{
waitEvent.WaitOne();
kernel.AddComponent(rand.Next() + ".common", typeof(ICommon), typeof(CommonImpl1));
Interlocked.Decrement(ref threadCount);
};
for(int i = 0; i < threadCount; i++)
{
ThreadPool.QueueUserWorkItem(addThread);
}
waitEvent.Set();
while(threadCount > 0 && list.Count == 0)
{
Thread.Sleep(15);
}
if (list.Count > 0)
{
Assert.Fail(list[0].ToString());
}
}
示例12: SetUpTests
public void SetUpTests()
{
kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
}
示例13: MultiThreadedAddResolve
public void MultiThreadedAddResolve([Values(100)] int threadCount)
{
object locker = new object();
IList<string> list = new List<string>();
ManualResetEvent waitEvent = new ManualResetEvent(false);
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());
kernel.AddComponent("common", typeof(ICommon), typeof(CommonImpl1));
WaitCallback resolveThread = delegate
{
waitEvent.WaitOne();
while(threadCount > 0 && list.Count == 0)
{
try
{
ICommon common = kernel[typeof(ICommon)] as ICommon;
}
catch(Exception e)
{
lock (locker)
{
list.Add(e.ToString());
}
}
}
};
ThreadPool.QueueUserWorkItem(resolveThread);
WaitCallback addThread = delegate
{
waitEvent.WaitOne();
kernel.AddComponent(Guid.NewGuid() + ".common", typeof(ICommon), typeof(CommonImpl1));
Interlocked.Decrement(ref threadCount);
};
for(int i = 0; i < threadCount; i++)
{
ThreadPool.QueueUserWorkItem(addThread);
}
waitEvent.Set();
while(threadCount > 0 && list.Count == 0)
{
Thread.Sleep(15);
}
if (list.Count > 0)
{
Assert.Fail(list[0].ToString());
}
}
示例14: SingleComponentUnregistersProperly
public void SingleComponentUnregistersProperly()
{
IKernel kernel = new DefaultKernel();
kernel.AddSubSystem(SubSystemConstants.NamingKey,
new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("1"); }));
kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("1.common"));
ICommon common = kernel[typeof(ICommon)] as ICommon;
Assert.IsNotNull(common);
Assert.AreEqual(typeof(CommonImpl1), common.GetType());
kernel.RemoveComponent("1.common");
Assert.IsFalse(kernel.HasComponent("1.common"));
Assert.IsFalse(kernel.HasComponent(typeof(CommonImpl1)));
common = kernel[typeof(ICommon)] as ICommon;
}