未验证 提交 7b5f81d0 编写于 作者: D Dan Siegel 提交者: GitHub

Merge pull request #2868 from PrismLibrary/ea-current

EA add static instance
......@@ -12,6 +12,7 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/Prism.Core/**'
- 'src/Prism.Events/**'
- 'tests/Prism.Core.Tests/**'
jobs:
......
......@@ -12,6 +12,7 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/Prism.Core/**'
- 'src/Prism.Events/**'
- 'tests/Prism.Core.Tests/**'
- 'src/Forms/**'
- 'tests/Forms/**'
......
......@@ -12,6 +12,7 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/Prism.Core/**'
- 'src/Prism.Events/**'
- 'tests/Prism.Core.Tests/**'
- 'src/Maui/**'
- 'tests/Containers/**'
......
......@@ -12,6 +12,7 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/Prism.Core/**'
- 'src/Prism.Events/**'
- 'tests/Prism.Core.Tests/**'
- 'src/Wpf/**'
- 'tests/Wpf/**'
......
......@@ -12,6 +12,7 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/Prism.Core/**'
- 'src/Prism.Events/**'
- 'tests/Prism.Core.Tests/**'
- 'src/Wpf/**'
- 'tests/Wpf/**'
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
namespace Prism.Events
......@@ -11,8 +10,30 @@ namespace Prism.Events
/// </summary>
public class EventAggregator : IEventAggregator
{
private static IEventAggregator _current;
/// <summary>
/// Gets or Sets the Current Instance of the <see cref="IEventAggregator"/>
/// </summary>
public static IEventAggregator Current
{
get => _current ??= new EventAggregator();
set => _current = value;
}
/// <summary>
/// Creates a new instance of the <see cref="EventAggregator"/>
/// </summary>
public EventAggregator()
{
if(_current is null)
{
_current = this;
}
}
private readonly Dictionary<Type, EventBase> events = new Dictionary<Type, EventBase>();
// Captures the sync context for the UI thread when constructed on the UI thread
// Captures the sync context for the UI thread when constructed on the UI thread
// in a platform agnostic way so it can be used for UI thread dispatching
private readonly SynchronizationContext syncContext = SynchronizationContext.Current;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册