本文整理汇总了C#中IServiceContainer.RemoveService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceContainer.RemoveService方法的具体用法?C# IServiceContainer.RemoveService怎么用?C# IServiceContainer.RemoveService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceContainer
的用法示例。
在下文中一共展示了IServiceContainer.RemoveService方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public static MenuCreationServiceContainer Get(IServiceContainer serviceContainer)
{
var current = serviceContainer.GetService<IMenuCreationService>();
var r = current as MenuCreationServiceContainer;
if (r == null)
{
r = new MenuCreationServiceContainer();
if (current != null)
{
r.Add(current);
serviceContainer.RemoveService(typeof(IMenuCreationService));
}
serviceContainer.AddService(typeof(IMenuCreationService), r);
}
return r;
}
示例2: AddThenRemoveService
private static void AddThenRemoveService(IServiceContainer sc)
{
object service = new object();
Type serviceType = service.GetType();
Assert.IsNull(sc.GetService(serviceType));
sc.AddService(serviceType, service);
Assert.AreSame(service, sc.GetService(serviceType));
sc.RemoveService(serviceType);
Assert.IsNull(sc.GetService(serviceType));
}
示例3: PublishService
/// <summary>
/// Publish application service to container
/// </summary>
private static void PublishService(Type type, object service, IServiceContainer serviceContainer, bool overwriteExistingService)
{
if (serviceContainer.GetService(type) != null)
{
if (overwriteExistingService)
{
serviceContainer.RemoveService(type, false);
serviceContainer.AddService(type, service);
}
}
else
{
serviceContainer.AddService(type, service);
}
}