本文整理汇总了C#中ServiceContainer.GetRequiredService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.GetRequiredService方法的具体用法?C# ServiceContainer.GetRequiredService怎么用?C# ServiceContainer.GetRequiredService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.GetRequiredService方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TagLineListForm
public TagLineListForm(IServiceProvider provider, IEnumerable<TagLineInfo> tagLines)
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));
if (tagLines == null)
throw new ArgumentNullException(nameof(tagLines));
_serviceManager = new ServiceContainer(provider);
_tagLines = new ObservableList<TagLineInfo>(tagLines);
InitializeComponent();
_serviceManager.Publish<ITagLineListFormService>(new TagLineListFormService(this));
_serviceManager.Publish<IDefaultCommandService>(new DefaultCommandService("Janus.Forum.TagLine.Edit"));
_toolbarGenerator = new StripMenuGenerator(_serviceManager, _toolStrip, "Forum.TagLine.Toolbar");
_contextMenuGenerator = new StripMenuGenerator(_serviceManager, _contextMenuStrip, "Forum.TagLine.ContextMenu");
_listImages.Images.Add(
_serviceManager.GetRequiredService<IStyleImageManager>()
.GetImage(@"MessageTree\Msg", StyleImageType.ConstSize));
UpdateData();
_tagLines.Changed += (sender, e) => UpdateData();
}
示例2: NotifyIconService
public NotifyIconService([NotNull] IServiceProvider serviceProvider)
{
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
_serviceManager = new ServiceContainer(serviceProvider);
_defaultCommandService = new DefaultCommandService("Janus.Application.ShowMainForm");
_serviceManager.Publish(_defaultCommandService);
_uiAsyncOperation = _serviceManager
.GetRequiredService<IUIShell>()
.CreateUIAsyncOperation();
_uiAsyncOperation.Send(
() =>
{
_notifyIcon = new NotifyIcon();
_notifyIcon.DoubleClick += NotifyIconDefaultAction;
_notifyIcon.BalloonTipClicked += NotifyIconDefaultAction;
Ticker.Instance.DoubleClick += NotifyIconDefaultAction;
});
}
示例3: Main
public static void Main()
{
TraceVerbose("Instance startup");
try
{
Console.WriteLine(
@"Janus project. Copyright (C) 2002-2012 by Rsdn Team. " +
@"See rsdn.ru for more information.");
// Проверка на единственность экземпляра приложения.
bool cn;
using (var m = new Mutex(true, "JanusRunningInstanceDetectionMutex", out cn))
{
if (!m.WaitOne(0, false))
{
WindowActivator.ActivateWindow(MainForm.GetCaption());
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Создаем контрол, чтобы инициализировать винформсный констекст синхронизации,
// если он еще не инициализирован
using (new Control()) { }
Thread.CurrentThread.CurrentUICulture = new CultureInfo((int)Config.Instance.UILanguage);
if (!CheckEnvironment())
return;
TraceVerbose("ResMgr");
var rootManager = new ServiceContainer(true);
rootManager.Publish<IUIShell>(
new UIShell(
() => ApplicationManager.Instance.MainForm,
freeze => ApplicationManager.Instance.MainForm.Enabled = freeze));
if (Config.Instance.ShowSplash)
{
EventHandler hider = null;
IDisposable informerCookie = null;
IDisposable progressCookie = null;
hider =
(sender, e) =>
{
progressCookie?.Dispose();
rootManager.Publish<IProgressService>(
new DefaultProgressService(rootManager));
informerCookie?.Dispose();
SplashHelper.Hide();
Application.Idle -= hider;
// ReSharper restore AccessToModifiedClosure
};
Application.Idle += hider;
informerCookie = rootManager.Publish(
SplashHelper.Show(rootManager));
progressCookie = rootManager.Publish(
SplashHelper.GetProgressService());
//Thread.Sleep(20000);
}
else
rootManager.Publish<IProgressService>(
new DefaultProgressService(rootManager));
using (var host = new JanusHost(rootManager))
{
using (host.InitScope())
{
rootManager.SetSplashMessage(SR.Splash.ApplicationStart);
TraceVerbose("JanusHost");
// Подписка сервиса на извещения об изменении конфигурации.
var configChangedNotifier = host.GetRequiredService<ConfigChangedNotifier>();
Config.Instance.ConfigChanged +=
(o, args) => configChangedNotifier.FireConfigChanged(Config.Instance);
try
{
//Проверка наличия пользователя
if (!LocalUser.UserExists())
using (var ouf = new OptionsUserForm(host, true))
ouf.ShowDialog();
rootManager.SetSplashMessage(SR.Splash.CheckDatabase);
if (!DBSchemaManager.CheckDB(host))
{
// User cancelled.
//
//.........这里部分代码省略.........