本文整理汇总了C#中IServiceContainer类的典型用法代码示例。如果您正苦于以下问题:C# IServiceContainer类的具体用法?C# IServiceContainer怎么用?C# IServiceContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IServiceContainer类属于命名空间,在下文中一共展示了IServiceContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCommonBody
private void TestCommonBody(IServiceContainer container, IList<String> expected)
{
IList<String> actual = container.ResolveNameTypeServices<String>();
Assert.That(actual.Count, Is.EqualTo(expected.Count));
foreach (String actualValue in actual)
Assert.True(expected.Contains(actualValue));
}
示例2: Detach
public void Detach(IServiceContainer container)
{
container.UnregisterService(mainForm);
mainForm.ServiceContainer = null;
mainForm = null;
}
示例3: Attach
public void Attach(IServiceContainer container)
{
mainForm = new MainForm();
mainForm.ServiceContainer = container;
container.RegisterService(mainForm);
}
示例4: CreateService
/// <summary>
/// This is the function that will create a new instance of the services the first time a client
/// will ask for a specific service type. It is called by the base class's implementation of
/// IServiceProvider.
/// </summary>
/// <param name="container">The IServiceContainer that needs a new instance of the service.
/// This must be this package.</param>
/// <param name="serviceType">The type of service to create.</param>
/// <returns>The instance of the service.</returns>
private object CreateService(IServiceContainer container, Type serviceType)
{
// Check if the IServiceContainer is this package.
if (container != this)
{
Debug.WriteLine("ServicesPackage.CreateService called from an unexpected service container.");
return null;
}
// Find the type of the requested service and create it.
if (typeof(SMyGlobalService).IsEquivalentTo(serviceType))
{
// Build the global service using this package as its service provider.
return new MyGlobalService(this);
}
if (typeof(SMyLocalService).IsEquivalentTo(serviceType))
{
// Build the local service using this package as its service provider.
return new MyLocalService(this);
}
// If we are here the service type is unknown, so write a message on the debug output
// and return null.
Debug.WriteLine("ServicesPackage.CreateService called for an unknown service type.");
return null;
}
示例5: DesignerHost
public DesignerHost(IServiceContainer parent)
{
// Keep the parent reference around for re-use
this.parent = parent;
// Initialise container helpers
components = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
designers = new Hashtable();
// Initialise transaction stack
transactions = new Stack();
// Add our own services
parent.AddService(typeof(IDesignerHost), this);
parent.AddService(typeof(IContainer), this);
parent.AddService(typeof(IComponentChangeService), this);
parent.AddService(typeof(ITypeDescriptorFilterService), this);
// Add extender services
extenderProviders = new ArrayList();
parent.AddService(typeof(IExtenderListService), this);
parent.AddService(typeof(IExtenderProviderService), this);
AddExtenderProvider(this);
// Add selection service
parent.AddService(typeof(ISelectionService), new SelectionService(this));
}
示例6: InitializeEnvironment
protected virtual void InitializeEnvironment(IServiceContainer container, ConfigurationManagerWrapper.ContentSectionTable config)
{
if (config.Web != null)
{
Url.DefaultExtension = config.Web.Web.Extension;
PathData.PageQueryKey = config.Web.Web.PageQueryKey;
PathData.ItemQueryKey = config.Web.Web.ItemQueryKey;
PathData.PartQueryKey = config.Web.Web.PartQueryKey;
PathData.PathKey = config.Web.Web.PathDataKey;
if (!config.Web.Web.IsWeb)
container.AddComponentInstance("n2.webContext.notWeb", typeof(IWebContext), new ThreadContext());
if (config.Web.Web.Urls.EnableCaching)
container.AddComponent("n2.web.cachingUrlParser", typeof(IUrlParser), typeof(CachingUrlParserDecorator));
if (config.Web.MultipleSites)
container.AddComponent("n2.multipleSitesParser", typeof(IUrlParser), typeof(MultipleSitesParser));
else
container.AddComponent("n2.urlParser", typeof(IUrlParser), typeof(UrlParser));
}
if (config.Management != null)
{
SelectionUtility.SelectedQueryKey = config.Management.Paths.SelectedQueryKey;
Url.SetToken("{Selection.SelectedQueryKey}", SelectionUtility.SelectedQueryKey);
}
}
示例7: LinFuServiceLocatorAdapter
public LinFuServiceLocatorAdapter(IServiceContainer container)
{
if (container == null)
throw new ArgumentNullException("container");
_container = container;
}
示例8: UndoEngineImplication
public UndoEngineImplication(IServiceContainer provider)
: base(provider)
{
service = provider;
editToolStripMenuItem = (ToolStripMenuItem)service.GetService(typeof(ToolStripMenuItem));
cassPropertyGrid = (FilteredPropertyGrid)service.GetService(typeof(FilteredPropertyGrid));
}
示例9: AddComponentUnlessConfigured
private void AddComponentUnlessConfigured(IServiceContainer container, Type serviceType, Type instanceType, IEnumerable<Type> skipList)
{
if (skipList.Contains(serviceType))
return;
container.AddComponent(serviceType.FullName + "->" + instanceType.FullName, serviceType, instanceType);
}
示例10: DefaultGetServiceBehavior
/// <summary>
/// Initializes the class with the given <paramref name="container"/> instance.
/// </summary>
/// <param name="container">The target service container.</param>
public DefaultGetServiceBehavior(IServiceContainer container)
{
_container = container;
_creator = new DefaultCreator();
_preProcessor = new CompositePreProcessor(container.PreProcessors);
_postProcessor = new CompositePostProcessor(container.PostProcessors);
}
示例11: GetService
protected override object GetService(Type serviceType)
{
object service = base.GetService(serviceType);
if (service != null)
{
return service;
}
if (serviceType == typeof(IServiceContainer))
{
if (this._services == null)
{
this._services = new ServiceContainer(this._host);
}
return this._services;
}
if (this._services != null)
{
return this._services.GetService(serviceType);
}
if ((base.Owner.Site != null) && this._safeToCallOwner)
{
try
{
this._safeToCallOwner = false;
return base.Owner.Site.GetService(serviceType);
}
finally
{
this._safeToCallOwner = true;
}
}
return null;
}
示例12: CreateService
private object CreateService(IServiceContainer container, Type serviceType)
{
if (serviceType == typeof(NpgsqlProviderObjectFactory))
return new NpgsqlProviderObjectFactory();
return null;
}
示例13: Detach
public void Detach(IServiceContainer container)
{
container.unregisterService(MainForm);
MainForm.ServiceContainer = null;
MainForm = null;
}
示例14: RegisterConfiguredComponents
protected virtual void RegisterConfiguredComponents(IServiceContainer container, EngineSection engineConfig)
{
foreach (ComponentElement component in engineConfig.Components)
{
Type implementation = Type.GetType(component.Implementation);
Type service = Type.GetType(component.Service);
if (implementation == null)
throw new ComponentRegistrationException(component.Implementation);
if (service == null && !String.IsNullOrEmpty(component.Service))
throw new ComponentRegistrationException(component.Service);
if (service == null)
service = implementation;
string name = component.Key;
if (string.IsNullOrEmpty(name))
name = implementation.FullName;
if (component.Parameters.Count == 0)
{
container.AddComponent(name, service, implementation);
}
else
{
container.AddComponentWithParameters(name, service, implementation,
component.Parameters.ToDictionary());
}
}
}
示例15: Deserialize
/// <summary>
/// Parses a source code and creates a new design surface.
/// </summary>
/// <param name="serviceContainer"></param>
/// <param name="surfaceManager"></param>
/// <param name="file">The source file to deserialize.</param>
/// <returns></returns>
public DesignSurface Deserialize(DesignSurfaceManager surfaceManager, IServiceContainer serviceContainer, OpenedFile file)
{
DesignSurface surface = surfaceManager.CreateDesignSurface(serviceContainer);
IDesignerHost designerHost = surface.GetService(typeof(IDesignerHost)) as IDesignerHost;
Type componentType = CompileTypeFromFile(file);
// load base type.
surface.BeginLoad(componentType.BaseType);
// get instance to copy components and properties from.
Control instance = Activator.CreateInstance(componentType) as Control;
// add components
var components = CreateComponents(componentType, instance, designerHost);
InitializeComponents(components, designerHost);
Control rootControl = designerHost.RootComponent as Control;
Control parent = rootControl.Parent;
ISite site = rootControl.Site;
// copy instance properties to root control.
CopyProperties(instance, designerHost.RootComponent);
rootControl.AllowDrop = true;
rootControl.Parent = parent;
rootControl.Visible = true;
rootControl.Site = site;
designerHost.RootComponent.Site.Name = instance.Name;
return surface;
}