本文整理汇总了C#中IServiceContainer.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceContainer.GetService方法的具体用法?C# IServiceContainer.GetService怎么用?C# IServiceContainer.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceContainer
的用法示例。
在下文中一共展示了IServiceContainer.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UndoEngineImplication
public UndoEngineImplication(IServiceContainer provider)
: base(provider)
{
service = provider;
editToolStripMenuItem = (ToolStripMenuItem)service.GetService(typeof(ToolStripMenuItem));
cassPropertyGrid = (FilteredPropertyGrid)service.GetService(typeof(FilteredPropertyGrid));
}
示例2: VerifyOncePerRequest
private static bool VerifyOncePerRequest(string serviceName, IServiceContainer container)
{
// The container must be able to create an
// ISampleService instance
Assert.IsTrue(container.Contains(serviceName, typeof(ISampleService)), "Service not found!");
// Both instances must be unique
var first = container.GetService<ISampleService>(serviceName);
var second = container.GetService<ISampleService>(serviceName);
Assert.AreNotSame(first, second, "The two instances returned from the container must be unique!");
return true;
}
示例3: PluginManager
/// <summary>
/// Initializes a new instance of the <see cref="PluginManager"/> class.
/// </summary>
/// <param name="serviceContainer">The service container.</param>
public PluginManager(IServiceContainer serviceContainer)
{
if (serviceContainer == null) throw new ArgumentNullException("serviceContainer");
services = serviceContainer;
settingsService = services.GetService<ISettingsService>(true);
}
示例4: GitStatusBarManager
protected GitStatusBarManager(Guid commandSetGuid, int branchMenuCmId, int branchCommandMenuCmId, int repositoryCommandMenuCmId, IServiceContainer serviceProvider, IStatusBarService statusBarService)
{
BranchMenuCmId = branchMenuCmId;
BranchCommandMenuCmId = branchCommandMenuCmId;
RepositoryCommandMenuCmId = repositoryCommandMenuCmId;
StatusBarService = statusBarService;
CommandSetGuid = commandSetGuid;
_menuCommandService = serviceProvider.GetService(typeof(IMenuCommandService)) as MsVsShell.OleMenuCommandService;
_serviceProvider = serviceProvider;
_branchCommandMenuCommands = new List<Tuple<string, MenuCommand>>();
}
示例5: DefaultRailsEngineContext
/// <summary>
/// Initializes a new instance of the <see cref="DefaultRailsEngineContext"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="urlInfo">Url information</param>
/// <param name="context">The context.</param>
/// <param name="container">External container instance</param>
public DefaultRailsEngineContext(IServiceContainer parent, UrlInfo urlInfo,
HttpContext context, IServiceProvider container)
: base(parent)
{
_urlInfo = urlInfo;
_context = context;
_request = new RequestAdapter(context.Request);
_trace = new TraceAdapter(context.Trace);
_server = new ServerUtilityAdapter(context.Server);
_response = new ResponseAdapter(context.Response, this, ApplicationPath);
_url = _context.Request.RawUrl;
_cache = parent.GetService(typeof(ICacheProvider)) as ICacheProvider;
this.container = container;
}
示例6: 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;
}
示例7: ResolveFrom
/// <summary>
/// Generates method arguments from the given <paramref name="parameterTypes"/>
/// and <paramref name="container"/>.
/// </summary>
/// <param name="parameterTypes">The parameter types for the target method.</param>
/// <param name="container">The container that will provide the method arguments.</param>
/// <param name="additionalArguments">The additional arguments that will be passed to the target method.</param>
/// <returns>An array of objects that represent the arguments to be passed to the target method.</returns>
public object[] ResolveFrom(IEnumerable<Type> parameterTypes, IServiceContainer container, params object[] additionalArguments)
{
var enumerableDefinition = typeof(IEnumerable<>);
var argumentList = new List<object>();
foreach (var parameterType in parameterTypes)
{
// Substitute the parameter if and only if
// the container does not have service that
// that matches the parameter type
var parameterTypeExists = container.Contains(parameterType);
if (parameterTypeExists)
{
// Instantiate the service type and build
// the argument list
object currentArgument = container.GetService(parameterType);
argumentList.Add(currentArgument);
continue;
}
// Determine if the parameter type is an IEnumerable<T> type
// and generate the list if necessary
if (parameterType.IsGenericType &&
parameterType.GetGenericTypeDefinition() == enumerableDefinition)
{
AddEnumerableArgument(parameterType, container, argumentList);
continue;
}
if (!parameterType.IsArray)
continue;
// Determine if the parameter type is an array
// of existing services and inject the current
// set of services as a parameter value
AddArrayArgument(parameterType, container, argumentList);
}
// Append the existing arguments
if (additionalArguments != null && additionalArguments.Length > 0)
argumentList.AddRange(additionalArguments);
return argumentList.ToArray();
}
示例8: VerifyOncePerThread
private static bool VerifyOncePerThread(string serviceName, IServiceContainer container)
{
var results = new List<ISampleService>();
Func<ISampleService> createService = () =>
{
var result = container.GetService<ISampleService>(serviceName);
lock (results)
{
results.Add(result);
}
return null;
};
Assert.IsTrue(container.Contains(serviceName, typeof(ISampleService)));
// Create the other instance from another thread
var asyncResult = createService.BeginInvoke(null, null);
// Two instances created within the same thread must be
// the same
var first = container.GetService<ISampleService>(serviceName);
var second = container.GetService<ISampleService>(serviceName);
Assert.IsNotNull(first);
Assert.AreSame(first, second);
// Wait for the other thread to finish executing
createService.EndInvoke(asyncResult);
Assert.IsTrue(results.Count > 0);
// The service instance created in the other thread
// must be unique
Assert.IsNotNull(results[0]);
Assert.AreNotSame(first, results[0]);
// NOTE: The return value will be ignored
return true;
}
示例9: Stop
internal static void Stop(IServiceContainer container)
{
var service = container.GetService(typeof(BooLanguageService))
as BooLanguageService;
if (service == null || service.mComponentId == 0)
return;
var mgr = container.GetService(typeof(SOleComponentManager))
as IOleComponentManager;
if (mgr != null)
{
mgr.FRevokeComponent(service.mComponentId);
}
service.mComponentId = 0;
}
示例10: Initialize
/// <summary>
/// Initializes the class with the <paramref name="source"/> container.
/// </summary>
/// <param name="source">The <see cref="IServiceContainer"/> instance that will create the class instance.</param>
public virtual void Initialize(IServiceContainer source)
{
Emitter = (IMethodBodyEmitter) source.GetService(typeof (IMethodBodyEmitter));
}
示例11: InitializeSurface
private void InitializeSurface ()
{
DesignSurface surface = new DesignSurfaceManager ().CreateDesignSurface ();
surface.BeginLoad (typeof (MyForm));
this._panelDesignerView.Controls.Add ((Control)surface.View);
((Control)surface.View).Dock = DockStyle.Fill;
this.serviceContainer = surface.GetService (typeof (IServiceContainer)) as IServiceContainer;
serviceContainer.AddService (typeof (IToolboxService), _toolbox);
ISelectionService s = (ISelectionService)serviceContainer.GetService (typeof (ISelectionService));
s.SelectionChanged += new EventHandler (OnSelectionChanged);
PopulateToolbox (_toolbox);
}
示例12: Initialize
/// <summary>
/// Initializes the current instance
/// with the <paramref name="source"/> container.
/// </summary>
/// <param name="source">The <see cref="IServiceContainer"/> instance that will hold the current instance.</param>
public void Initialize(IServiceContainer source)
{
ProxyImplementor = (ITypeBuilder) source.GetService("ProxyImplementor", typeof (ITypeBuilder));
MethodPicker = (IMethodPicker) source.GetService(typeof (IMethodPicker));
ProxyMethodBuilder = (IMethodBuilder) source.GetService("ProxyMethodBuilder", typeof (IMethodBuilder));
}
示例13: Initialize
public void Initialize(IServiceContainer container)
{
_engine = container.GetService<IEngine>();
_person = container.GetService<IPerson>();
}
示例14: OnCreateLuaLanguageService
/// <summary>
///
/// </summary>
/// <param name="container"></param>
/// <param name="serviceType"></param>
/// <returns></returns>
private static ILuaLanguageService OnCreateLuaLanguageService(IServiceContainer container, Type serviceType)
{
if (serviceType == typeof(ILuaLanguageService))
return container.GetService(typeof(LanguageService)) as ILuaLanguageService;
return null;
}
示例15: Initialize
public void Initialize(IServiceContainer source)
{
_createAdapterType = source.GetService<ITypeBuilder>("CreateAdapterType");
}