Browse Source

Replace ServiceLocator with Splat.Locator.

pull/4/head
Steven Kirk 12 years ago
parent
commit
77b1f1e15f
  1. 3
      Perspex/Controls/TextBlock.cs
  2. 1
      Perspex/Perspex.csproj
  3. 27
      Perspex/ServiceLocator.cs
  4. 3
      TestApplication/Program.cs

3
Perspex/Controls/TextBlock.cs

@ -7,6 +7,7 @@
namespace Perspex.Controls namespace Perspex.Controls
{ {
using Perspex.Media; using Perspex.Media;
using Splat;
public class TextBlock : Control public class TextBlock : Control
{ {
@ -57,7 +58,7 @@ namespace Perspex.Controls
protected override Size MeasureContent(Size availableSize) protected override Size MeasureContent(Size availableSize)
{ {
ITextService service = ServiceLocator.Get<ITextService>(); ITextService service = Locator.Current.GetService<ITextService>();
return service.Measure(this.FormattedText); return service.Measure(this.FormattedText);
} }
} }

1
Perspex/Perspex.csproj

@ -115,7 +115,6 @@
<Compile Include="Styling\Selector.cs" /> <Compile Include="Styling\Selector.cs" />
<Compile Include="RoutedEventArgs.cs" /> <Compile Include="RoutedEventArgs.cs" />
<Compile Include="Styling\Selectors.cs" /> <Compile Include="Styling\Selectors.cs" />
<Compile Include="ServiceLocator.cs" />
<Compile Include="Setter.cs" /> <Compile Include="Setter.cs" />
<Compile Include="Size.cs" /> <Compile Include="Size.cs" />
<Compile Include="Rect.cs" /> <Compile Include="Rect.cs" />

27
Perspex/ServiceLocator.cs

@ -1,27 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="ServiceLocator.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using System.Collections.Generic;
public static class ServiceLocator
{
private static Dictionary<Type, Func<object>> services =
new Dictionary<Type, Func<object>>();
public static T Get<T>()
{
return (T)services[typeof(T)]();
}
public static void Register<T>(Func<T> func)
{
services.Add(typeof(T), () => (object)func());
}
}
}

3
TestApplication/Program.cs

@ -37,7 +37,8 @@ namespace TestApplication
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ServiceLocator.Register<ITextService>(() => new TextService(new SharpDX.DirectWrite.Factory())); Locator.CurrentMutable.Register(() => new TextService(new SharpDX.DirectWrite.Factory()), typeof(ITextService));
Locator.CurrentMutable.Register(() => new Styler(), typeof(IStyler));
Locator.CurrentMutable.Register(() => new TestLogger(), typeof(ILogger)); Locator.CurrentMutable.Register(() => new TestLogger(), typeof(ILogger));
Application application = new Application Application application = new Application

Loading…
Cancel
Save