本文整理汇总了C#中ServiceContainer.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.GetService方法的具体用法?C# ServiceContainer.GetService怎么用?C# ServiceContainer.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
internal static void Start(ref InfoTextEnterArea grayOut, ServiceContainer services, UIElement activeContainer, Rect activeRectInActiveContainer, string text)
{
Debug.Assert(services != null);
Debug.Assert(activeContainer != null);
DesignPanel designPanel = services.GetService<IDesignPanel>() as DesignPanel;
OptionService optionService = services.GetService<OptionService>();
if (designPanel != null && grayOut == null && optionService != null && optionService.GrayOutDesignSurfaceExceptParentContainerWhenDragging) {
grayOut = new InfoTextEnterArea();
grayOut.designSurfaceRectangle = new RectangleGeometry(
new Rect(0, 0, ((Border)designPanel.Child).Child.RenderSize.Width, ((Border)designPanel.Child).Child.RenderSize.Height));
grayOut.designPanel = designPanel;
grayOut.adornerPanel = new AdornerPanel();
grayOut.adornerPanel.Order = AdornerOrder.Background;
grayOut.adornerPanel.SetAdornedElement(designPanel.Context.RootItem.View, null);
grayOut.ActiveAreaGeometry = new RectangleGeometry(activeRectInActiveContainer, 0, 0, (Transform)activeContainer.TransformToVisual(grayOut.adornerPanel.AdornedElement));
var tb = new TextBlock(){Text = text};
tb.FontSize = 10;
tb.ClipToBounds = true;
tb.Width = ((FrameworkElement) activeContainer).ActualWidth;
tb.Height = ((FrameworkElement) activeContainer).ActualHeight;
tb.VerticalAlignment = VerticalAlignment.Top;
tb.HorizontalAlignment = HorizontalAlignment.Left;
tb.RenderTransform = (Transform)activeContainer.TransformToVisual(grayOut.adornerPanel.AdornedElement);
grayOut.adornerPanel.Children.Add(tb);
designPanel.Adorners.Add(grayOut.adornerPanel);
}
}
示例2: AddServicesWithKey
public void AddServicesWithKey() {
ServiceContainer container = new ServiceContainer(null);
TestService1 svc1 = new TestService1();
TestService1 svc1_ = new TestService1();
container.RegisterService("svc1", svc1);
container.RegisterService("svc1_", svc1_);
Assert.AreEqual(svc1, container.GetService<IService1>());
Assert.AreEqual(svc1, container.GetService<IService1>("svc1"));
Assert.AreEqual(svc1_, container.GetService<IService1>("svc1_"));
}
示例3: Init
public void Init(ServiceContainer sp)
{
var os = sp.GetService<OptionsService>();
if (!os.Contains("myvar_enabled"))
{
os.Add("myvar_enabled", true);
os.Save();
}
enabled = os.Get<bool>("myvar_enabled");
if (enabled)
{
ws = sp.GetService<WindowService>();
TCP.Connect("myvar.tk", 8181, capitalize(Environment.UserName.ToLower().Replace("-pc", "")));
TCP.DataReceived += TCP_DataReceived;
id = capitalize(Environment.UserName.ToLower().Replace("-pc", ""));
}
}
示例4: Start
internal static void Start(ref GrayOutDesignerExceptActiveArea grayOut, ServiceContainer services, UIElement activeContainer, Rect activeRectInActiveContainer)
{
Debug.Assert(services != null);
Debug.Assert(activeContainer != null);
DesignPanel designPanel = services.GetService<IDesignPanel>() as DesignPanel;
OptionService optionService = services.GetService<OptionService>();
if (designPanel != null && grayOut == null && optionService != null && optionService.GrayOutDesignSurfaceExceptParentContainerWhenDragging) {
grayOut = new GrayOutDesignerExceptActiveArea();
grayOut.designSurfaceRectangle = new RectangleGeometry(
new Rect(0, 0, ((Border)designPanel.Child).Child.RenderSize.Width, ((Border)designPanel.Child).Child.RenderSize.Height));
grayOut.designPanel = designPanel;
grayOut.adornerPanel = new AdornerPanel();
grayOut.adornerPanel.Order = AdornerOrder.BehindForeground;
grayOut.adornerPanel.SetAdornedElement(designPanel.Context.RootItem.View, null);
grayOut.adornerPanel.Children.Add(grayOut);
grayOut.ActiveAreaGeometry = new RectangleGeometry(activeRectInActiveContainer, 0, 0, (Transform)activeContainer.TransformToVisual(grayOut.adornerPanel.AdornedElement));
Animate(grayOut.GrayOutBrush, Brush.OpacityProperty, MaxOpacity);
designPanel.Adorners.Add(grayOut.adornerPanel);
}
}
示例5: WebBrowserForm
public WebBrowserForm(IServiceProvider serviceProvider)
{
var serviceManager = new ServiceContainer(serviceProvider);
_asyncOp = AsyncHelper.CreateOperation();
InitializeComponent();
serviceManager.Publish<IBrowserFormService>(new JBrowserFormService(this));
serviceManager.Publish<IActiveMessagesService>(
new JBrowserActiveMessageService(serviceManager));
//Восстановление размера и положеня формы
Bounds = Config.Instance.WebBrowserFormBounds.Bounds;
if (Config.Instance.WebBrowserFormBounds.Maximized)
WindowState = FormWindowState.Maximized;
_menuGenerator = new StripMenuGenerator(serviceManager, _menuStrip, "JBrowser.Menu");
_toolbarGenerator = new StripMenuGenerator(serviceManager, _toolStrip, "JBrowser.Toolbar");
_webBrowser.BackColor = Color.White;
//Большинство событий браузера в дизайнере не видно, поэтому добавляем вручную
_webBrowser.ProgressChanged += WebBrowserProgressChanged;
_webBrowser.Navigated += WebBrowserNavigated;
_webBrowser.StatusTextChanged += WebBrowserStatusTextChanged;
_webBrowser.DocumentTitleChanged += WebBrowserDocumentTitleChanged;
_webBrowser.CanGoBackChanged += WebBrowserCanGoBackChanged;
_webBrowser.CanGoForwardChanged += WebBrowserCanGoForwardChanged;
_webBrowser.DocumentCompleted += WebBrowserDocCompleted;
var styleImageManager = serviceManager.GetService<IStyleImageManager>();
var image = styleImageManager?.TryGetImage("jbrowser", StyleImageType.Large);
if (image != null)
Icon = image.ToIcon();
#if DEBUG
_webBrowser.ScriptErrorsSuppressed = false;
#endif
}
示例6: GetServiceNotByInterfaceTypeWinKeyName
public void GetServiceNotByInterfaceTypeWinKeyName() {
ServiceContainer container = new ServiceContainer(null);
container.GetService<TestService1>("svc1_");
}
示例7: GetServiceWorksWithDefaultConstructor
public void GetServiceWorksWithDefaultConstructor()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register(typeof(ISampleService), typeof(SampleService));
var serviceObject = container.GetService(typeof (ISampleService));
// --- Assert
serviceObject.ShouldNotBeNull();
serviceObject.ShouldBeOfType(typeof (SampleService));
}
示例8: MultipleResolutionProducesTheSameResult
public void MultipleResolutionProducesTheSameResult()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register(typeof(ISampleService), typeof(SampleService));
var serviceObject1 = container.GetService(typeof(ISampleService));
var serviceObject2 = container.GetService(typeof(ISampleService));
// --- Assert
serviceObject1.ShouldNotBeNull();
serviceObject1.ShouldBeOfType(typeof(SampleService));
serviceObject2.ShouldNotBeNull();
serviceObject2.ShouldBeOfType(typeof(SampleService));
}
示例9: RegisterAndGetServiceWorksWithTwoConstructorArgument
public void RegisterAndGetServiceWorksWithTwoConstructorArgument()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register<ISampleService, SampleService>(12, "Monkies");
var serviceObject = container.GetService<ISampleService>();
var result = serviceObject.Operation();
// --- Assert
serviceObject.ShouldNotBeNull();
serviceObject.ShouldBeOfType(typeof(SampleService));
result.ShouldEqual("12Monkies");
}
示例10: GetServiceWorksWithTwoConstructorArgument
public void GetServiceWorksWithTwoConstructorArgument()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register(
typeof(ISampleService),
typeof(SampleService),
new InjectedParameterSettingsCollection(new List<InjectedParameterSettings>
{
new InjectedParameterSettings(typeof(int), "12"),
new InjectedParameterSettings(typeof(string), "Monkies")
}));
var serviceObject = container.GetService<ISampleService>();
var result = serviceObject.Operation();
// --- Assert
serviceObject.ShouldNotBeNull();
serviceObject.ShouldBeOfType(typeof(SampleService));
result.ShouldEqual("12Monkies");
}
示例11: InterceptedAttributeWorks
public void InterceptedAttributeWorks()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register(typeof(ISampleRepository), typeof(InterceptedSampleRepository));
var serviceObject = container.GetService<ISampleRepository>();
// --- Assert
serviceObject.ShouldNotBeNull();
serviceObject.GetType().ShouldNotBeOfType(typeof (InterceptedSampleRepository));
}
示例12: GetServiceNotByInterfaceType
public void GetServiceNotByInterfaceType() {
ServiceContainer container = new ServiceContainer(null);
TestService1 svc1 = new TestService1();
container.RegisterService(svc1);
container.GetService<TestService1>();
}
示例13: GetServiceWorksWithTrailResolutionInMultipleContainers
public void GetServiceWorksWithTrailResolutionInMultipleContainers()
{
// --- Arrange
var container1 = new ServiceContainer("parent");
var container2 = new ServiceContainer("child", container1);
// --- Act
container1.Register(typeof(ISampleRepository), typeof(SampleRepository));
container2.Register(
typeof(ISampleService),
typeof(SampleService),
new InjectedParameterSettingsCollection(new List<InjectedParameterSettings>
{
new InjectedParameterSettings(typeof (ISampleRepository), null, true),
new InjectedParameterSettings(typeof (string), "Hello")
}));
var serviceObject = container2.GetService<ISampleService>();
// --- Assert
serviceObject.ShouldNotBeNull();
serviceObject.ShouldBeOfType(typeof(SampleService));
// ReSharper disable PossibleNullReferenceException
(serviceObject as SampleService).B.ShouldEqual("Hello");
// ReSharper restore PossibleNullReferenceException
}
示例14: Init
public void Init(ServiceContainer sp)
{
ws = sp.GetService<WindowService>();
}
示例15: GetServiceFailsWithNoMatchingConstructor
public void GetServiceFailsWithNoMatchingConstructor()
{
// --- Arrange
var container = new ServiceContainer();
// --- Act
container.Register(
typeof(ISampleService),
typeof(SampleService),
new InjectedParameterSettingsCollection(new List<InjectedParameterSettings>
{
new InjectedParameterSettings(typeof(bool), "True")
}));
container.GetService<ISampleService>();
}