本文整理汇总了C#中ServiceProvider.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider.GetService方法的具体用法?C# ServiceProvider.GetService怎么用?C# ServiceProvider.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceProvider
的用法示例。
在下文中一共展示了ServiceProvider.GetService方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDataPersistence
public void TestDataPersistence()
{
IService srv;
srv = new GenericSingletonService<IContract, ContractImplementation>();
ServiceProvider container = new ServiceProvider();
container.RegisterService<IContract>(srv);
IContract imp;
imp = container.GetService<IContract>();
imp.Name = "asdf";
Assert.AreEqual("asdf", imp.Name);
imp = container.GetService<IContract>();
//verify that the name has persisted.
Assert.AreEqual("asdf", imp.Name);
}
示例2: DocumentProperties
/// <include file='doc\CodeWindowManager.uex' path='docs/doc[@for="DocumentProperties.DocumentProperties"]/*' />
protected DocumentProperties(CodeWindowManager mgr) {
this.mgr = mgr;
this.visible = true;
if (mgr != null) {
IOleServiceProvider sp = mgr.CodeWindow as IOleServiceProvider;
if (sp != null) {
ServiceProvider site = new ServiceProvider(sp);
this.tracker = site.GetService(typeof(SVsTrackSelectionEx)) as IVsTrackSelectionEx;
}
}
}
示例3: SelectionListener
protected SelectionListener(ServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
this.monSel = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
Debug.Assert(this.monSel != null, "Could not get the IVsMonitorSelection object from the services exposed by this project");
if (this.monSel == null)
{
throw new InvalidOperationException();
}
}
示例4: ProjectDocumentsListener
protected ProjectDocumentsListener(ServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
this.projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
Debug.Assert(this.projectDocTracker != null, "Could not get the IVsTrackProjectDocuments2 object from the services exposed by this project");
if (this.projectDocTracker == null)
{
throw new InvalidOperationException();
}
}
示例5: GetService
public void GetService()
{
SqlServer2000Platform sqlServer2000Platform = new SqlServer2000Platform();
IServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.RegisterService(sqlServer2000Platform);
Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService<IDbPlatform>());
Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService(typeof(IDbPlatform)));
Assert.AreSame(sqlServer2000Platform, serviceProvider.GetService<SqlServer2000Platform>());
serviceProvider.RegisterService(typeof(IDbTypeMapper), delegate { return new SqlServer2000TypeMapper(); });
IDbTypeMapper dbTypeMapper = serviceProvider.GetService<IDbTypeMapper>();
Assert.IsNotNull(dbTypeMapper);
Assert.AreNotSame(dbTypeMapper, serviceProvider.GetService<IDbTypeMapper>());
serviceProvider.RegisterService<IDbNamingStrategy>(delegate { return new SqlServer2000NamingStrategy(); });
IDbNamingStrategy dbNamingStrategy = serviceProvider.GetService<IDbNamingStrategy>();
Assert.IsNotNull(dbNamingStrategy);
Assert.AreNotSame(dbNamingStrategy, serviceProvider.GetService<IDbNamingStrategy>());
}
示例6: TestBase
protected TestBase ()
{
mServiceProvider = ServiceProvider.Instance;
SqlHelper.InitDatabase();
LoginService = mServiceProvider.GetService<IWcfLoginService>();
SystemService = mServiceProvider.GetService<IWcfSystemService>();
DianpuService = mServiceProvider.GetService<IWcfDianpuService>();
BiaoService = mServiceProvider.GetService<IWcfBiaoService>();
HelpService = mServiceProvider.GetService<IWcfHelpService>();
FuwuqiService = mServiceProvider.GetService<IWcfFuwuqiService>();
JubenService = mServiceProvider.GetService<IWcfJubenService>();
XiakeService = mServiceProvider.GetService<IWcfXiakeService>();
GonggaoService = mServiceProvider.GetService<IWcfGonggaoService>();
BiaoshiService = mServiceProvider.GetService<IWcfBiaoshiService>();
ChargeService = mServiceProvider.GetService<IWcfChargeService>();
ValidationService = mServiceProvider.GetService<IWcfValidationService>();
DingdanService = mServiceProvider.GetService<IWcfDingdanService>();
RenwuService = mServiceProvider.GetService<IWcfRenwuService>();
PayService = mServiceProvider.GetService<IWcfPayService>();
InviteIncomeController = mServiceProvider.GetService<InviteIncomeController>();
RenwuHandleController = mServiceProvider.GetService<RenwuHandleController>();
PayHandleController = mServiceProvider.GetService<PayHandleController>();
}
示例7: Setup
public void Setup()
{
ServiceProvider provider = new ServiceProvider();
queryBuilder = (IWikiQueryBuilder)provider.GetService(typeof(IWikiQueryBuilder));
}
示例8: GetService
//
// Summary:
// Returns an object that represents a service provided by the System.ComponentModel.Component
// or by its System.ComponentModel.Container.
//
// Parameters:
// service:
// A service provided by the System.ComponentModel.Component.
//
// Returns:
// An System.Object that represents a service provided by the System.ComponentModel.Component,
// or null if the System.ComponentModel.Component does not provide the specified
// service.
protected override object GetService(Type service)
{
if (_vsServiceProvider != null)
{
ServiceProvider sp = new ServiceProvider(_vsServiceProvider);
return sp.GetService(service);
}
return null;
}
示例9: GetCodeWindowManager
// GetCodeWindowManager -- this gives us the VsCodeWindow which is what we need to
// add adornments and so forth.
/// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.GetCodeWindowManager"]/*' />
public int GetCodeWindowManager(IVsCodeWindow codeWindow, out IVsCodeWindowManager mgr)
{
//set the inheritKeyBinding guid so that navigation keys work. Do this before deriving class's
//CreateCodeWindowManager method gets called, so they may override if required
IOleServiceProvider sp = codeWindow as IOleServiceProvider;
if (sp != null) {
ServiceProvider site = new ServiceProvider(sp);
object window = site.GetService(typeof(IVsWindowFrame).GUID);
if (window is IVsWindowFrame) {
IVsWindowFrame frame = (IVsWindowFrame)window;
Guid CMDUIGUID_TextEditor = new Guid(0x8B382828, 0x6202, 0x11d1, 0x88, 0x70, 0x00, 0x00, 0xF8, 0x75, 0x79, 0xD2);
NativeMethods.ThrowOnFailure(frame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref CMDUIGUID_TextEditor));
}
}
Initialize();
IVsTextLines buffer = null;
NativeMethods.ThrowOnFailure(codeWindow.GetBuffer(out buffer));
mgr = CreateCodeWindowManager(codeWindow, GetOrCreateSource(buffer));
return NativeMethods.S_OK;
}