Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@code {
// If you want to use this razor component in standalone mode,
// you can use a nullable IMessageBarInstance property.
// If the value is not null, the component is running using the MessageBarService.
// If the value is not null, the component is running using the NotificationService.
// `public IMessageBarInstance? MessageBar { get; set; }`
[CascadingParameter]
public required IMessageBarInstance MessageBar { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IMessageBarService MessageBarService
@inject INotificationService NotificationService

<FluentMessageBarProvider Section="@MESSAGEBAR_SECTION"
Margin="@Margin.Vertical2" />
Expand All @@ -20,12 +20,12 @@

async Task ShowCustomizedMessageBar()
{
var result = await MessageBarService.ShowMessageAsync<Message.CustomizedMessageBar>(options =>
var result = await NotificationService.ShowMessageBarAsync<Message.CustomizedMessageBar>(options =>
{
options.Section = MESSAGEBAR_SECTION;

options.Intent = MessageBarIntent.Success;
options.Title = "Hello from the MessageBarService!";
options.Title = "Hello from the NotificationService!";
options.Lifetime = TimeSpan.FromSeconds(10);
});

Expand All @@ -34,11 +34,11 @@

async Task ShowCustomizedComponent()
{
var result = await MessageBarService.ShowMessageAsync<Message.CustomizedComponent>(options =>
var result = await NotificationService.ShowMessageBarAsync<Message.CustomizedComponent>(options =>
{
options.Section = MESSAGEBAR_SECTION;

options.Title = "Hello from the MessageBarService!";
options.Title = "Hello from the NotificationService!";
options.Lifetime = TimeSpan.FromSeconds(5);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
@inject IMessageBarService MessageBarService
@inject INotificationService NotificationService

<FluentMessageBarProvider Section="@MESSAGEBAR_SECTION"
Margin="@Margin.Vertical2" />

<FluentButton OnClick="@(async e => await MessageBarService.ShowSuccessMessageAsync(MESSAGEBAR_SECTION, title: "This is a success message bar"))">
<FluentButton OnClick="@(async e => await NotificationService.ShowSuccessBarAsync(MESSAGEBAR_SECTION, title: "This is a success message bar"))">
Success
</FluentButton>

<FluentButton OnClick="@(async e => await MessageBarService.ShowWarningMessageAsync(MESSAGEBAR_SECTION, title: "This is a warning message bar"))">
<FluentButton OnClick="@(async e => await NotificationService.ShowWarningBarAsync(MESSAGEBAR_SECTION, title: "This is a warning message bar"))">
Warning
</FluentButton>

<FluentButton OnClick="@(async e => await MessageBarService.ShowErrorMessageAsync(MESSAGEBAR_SECTION, title: "This is an error message bar"))">
<FluentButton OnClick="@(async e => await NotificationService.ShowErrorBarAsync(MESSAGEBAR_SECTION, title: "This is an error message bar"))">
Error
</FluentButton>

<FluentButton OnClick="@(async e => await MessageBarService.ShowInfoMessageAsync(MESSAGEBAR_SECTION, title: "This is an info message bar"))">
<FluentButton OnClick="@(async e => await NotificationService.ShowInfoBarAsync(MESSAGEBAR_SECTION, title: "This is an info message bar"))">
Info
</FluentButton>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IMessageBarService MessageBarService
@inject INotificationService NotificationService

<FluentMessageBarProvider Section="@MESSAGEBAR_SECTION"
Margin="@Margin.Vertical2" />
Expand All @@ -14,7 +14,7 @@

async Task ShowMessageBar()
{
var result = await MessageBarService.ShowMessageAsync(options =>
var result = await NotificationService.ShowMessageBarAsync(options =>
{
options.Section = MESSAGEBAR_SECTION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ If you want to display an Action and a TimeStamp, you can use the `ActionsTempla

{{ MessageBarLayouts }}

## Message Service
## Notification Service

Use the `MessageBarService` to display message bars from C# code (for example, from an event handler, a service, or after an API call).
Use the `NotificationService` to display message bars from C# code (for example, from an event handler, a service, or after an API call).

The service is registered automatically when you call `AddFluentUIComponents()` in your `Program.cs`:

You can then inject it into any component or service:

```csharp
@inject IMessageBarService MessageBarService
@inject INotificationService NotificationService
```

**FluentMessageBarProvider**
Expand All @@ -76,10 +76,10 @@ and a local provider scoped to a specific panel or dialog), and to route each me

The simplest way to display a message is to use one of the typed helpers, passing the target section and the message text:

- `MessageBarService.ShowSuccessMessageAsync("SECTION", "Title", "Message")`
- `MessageBarService.ShowWarningMessageAsync("SECTION", "Title", "Message")`
- `MessageBarService.ShowErrorMessageAsync("SECTION", "Title", "Message")`
- `MessageBarService.ShowInfoMessageAsync("SECTION", "Title", "Message")`
- `NotificationService.ShowSuccessBarAsync("SECTION", "Title", "Message")`
- `NotificationService.ShowWarningBarAsync("SECTION", "Title", "Message")`
- `NotificationService.ShowErrorBarAsync("SECTION", "Title", "Message")`
- `NotificationService.ShowInfoBarAsync("SECTION", "Title", "Message")`
Comment thread
dvoituron marked this conversation as resolved.

{{ MessageBarServiceDefault }}

Expand All @@ -101,9 +101,9 @@ This is useful when the default layout is not enough and you need to render rich

{{ API Type=FluentMessageBar }}

## API MessageBarService
## API NotificationService

{{ API Type=MessageBarService }}
{{ API Type=NotificationService }}
Comment thread
dvoituron marked this conversation as resolved.

## API MessageBarOptions

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Components/MessageBar/FluentMessageBar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FluentMessageBar(LibraryConfiguration configuration) : base(configuration
.Build();

/// <summary>
/// Gets the instance, if the message is rendered using the <see cref="IMessageBarService"/>. Otherwise, returns null.
/// Gets the instance, if the message is rendered using the <see cref="INotificationService"/>. Otherwise, returns null.
/// </summary>
[CascadingParameter]
internal IMessageBarInstance? MessageBarInstance { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class="@ClassValue"
style="@StyleValue"
@attributes="AdditionalAttributes">
@if (MessageBarService != null)
@if (NotificationService != null)
{
@foreach (var messageBar in GetRenderedMessageBars())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Container component that renders all message bars registered with the <see cref="IMessageBarService"/>.
/// Container component that renders all message bars registered with the <see cref="INotificationService"/>.
/// </summary>
public partial class FluentMessageBarProvider : FluentComponentBase, IDisposable
{
Expand Down Expand Up @@ -36,14 +36,14 @@ public FluentMessageBarProvider(LibraryConfiguration configuration) : base(confi
public required string Section { get; set; }

/// <summary />
protected virtual IMessageBarService? MessageBarService => GetCachedServiceOrNull<IMessageBarService>();
protected virtual INotificationService? NotificationService => GetCachedServiceOrNull<INotificationService>();

/// <summary />
protected override void OnInitialized()
{
base.OnInitialized();

if (MessageBarService is MessageBarService service)
if (NotificationService is NotificationService service)
{
// Register this provider as a subscriber. Multiple providers can coexist:
// each one is notified and decides (via Section) which messages to render.
Expand All @@ -54,15 +54,15 @@ protected override void OnInitialized()
/// <summary />
public void Dispose()
{
if (MessageBarService is MessageBarService service && !string.IsNullOrEmpty(Id))
if (NotificationService is NotificationService service && !string.IsNullOrEmpty(Id))
{
service.Unsubscribe(Id);
}
}

/// <summary />
private IEnumerable<IMessageBarInstance> GetRenderedMessageBars()
=> MessageBarService?.Items.Values
=> NotificationService?.Items.Values
.Where(messageBar => string.Compare(messageBar.Options.Section, Section, StringComparison.OrdinalIgnoreCase) == 0 &&
messageBar.LifecycleStatus == MessageBarLifecycleStatus.Visible)
.OrderBy(messageBar => messageBar.Index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Interface for a message bar instance managed by the <see cref="IMessageBarService"/>.
/// Interface for a message bar instance managed by the <see cref="INotificationService"/>.
/// </summary>
public interface IMessageBarInstance
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
/// <summary>
/// Interface for the MessageBar service.
/// </summary>
public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
public partial interface INotificationService : IFluentServiceBase<IMessageBarInstance>
{
/// <summary>
/// Shows a success message bar with the specified title and message and waits for the close result.
Expand All @@ -19,7 +19,7 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// <param name="title">The title of the message bar.</param>
/// <param name="message">The message content of the message bar.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the close result of the message bar.</returns>
Task<MessageBarResult> ShowSuccessMessageAsync(string section, string? title = null, string? message = null);
Task<MessageBarResult> ShowSuccessBarAsync(string section, string? title = null, string? message = null);

/// <summary>
/// Shows a warning message bar with the specified title and message and waits for the close result.
Expand All @@ -28,7 +28,7 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// <param name="title">The title of the message bar.</param>
/// <param name="message">The message content of the message bar.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the close result of the message bar.</returns>
Task<MessageBarResult> ShowWarningMessageAsync(string section, string? title = null, string? message = null);
Task<MessageBarResult> ShowWarningBarAsync(string section, string? title = null, string? message = null);

/// <summary>
/// Shows an error message bar with the specified title and message and waits for the close result.
Expand All @@ -37,7 +37,7 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// <param name="title">The title of the message bar.</param>
/// <param name="message">The message content of the message bar.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the close result of the message bar.</returns>
Task<MessageBarResult> ShowErrorMessageAsync(string section, string? title = null, string? message = null);
Task<MessageBarResult> ShowErrorBarAsync(string section, string? title = null, string? message = null);

/// <summary>
/// Shows an informational message bar with the specified title and message and waits for the close result.
Expand All @@ -46,27 +46,27 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// <param name="title">The title of the message bar.</param>
/// <param name="message">The message content of the message bar.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the close result of the message bar.</returns>
Task<MessageBarResult> ShowInfoMessageAsync(string section, string? title = null, string? message = null);
Task<MessageBarResult> ShowInfoBarAsync(string section, string? title = null, string? message = null);

/// <summary>
/// Shows a message bar using the supplied options and waits for the close result.
/// </summary>
/// <param name="options">Options to configure the message bar.</param>
Task<MessageBarResult> ShowMessageAsync(MessageBarOptions options);
Task<MessageBarResult> ShowMessageBarAsync(MessageBarOptions options);

/// <summary>
/// Shows a message bar by configuring an options object and waits for the close result.
/// </summary>
/// <param name="options">Action used to configure the message bar.</param>
Task<MessageBarResult> ShowMessageAsync(Action<MessageBarOptions> options);
Task<MessageBarResult> ShowMessageBarAsync(Action<MessageBarOptions> options);

/// <summary>
/// Shows a custom message bar component and waits for the close result.
/// The component receives the current <see cref="IMessageBarInstance"/> through a cascading parameter.
/// </summary>
/// <typeparam name="TMessageBar">A Blazor component type used to render the message bar.</typeparam>
/// <param name="options">Options used to configure the message bar.</param>
Task<MessageBarResult> ShowMessageAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessageBar>(MessageBarOptions options)
Task<MessageBarResult> ShowMessageBarAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessageBar>(MessageBarOptions options)
where TMessageBar : ComponentBase;

/// <summary>
Expand All @@ -75,7 +75,7 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// </summary>
/// <typeparam name="TMessageBar">A Blazor component type used to render the message bar.</typeparam>
/// <param name="options">Action used to configure the message bar.</param>
Task<MessageBarResult> ShowMessageAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessageBar>(Action<MessageBarOptions> options)
Task<MessageBarResult> ShowMessageBarAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessageBar>(Action<MessageBarOptions> options)
where TMessageBar : ComponentBase;

/// <summary>
Expand All @@ -97,5 +97,5 @@ public interface IMessageBarService : IFluentServiceBase<IMessageBarInstance>
/// Closes all current message bars.
/// </summary>
/// <returns>The number of message bars that were closed.</returns>
Task<int> CloseAllAsync();
Task<int> CloseAllMessageBarsAsync();
}
16 changes: 8 additions & 8 deletions src/Core/Components/MessageBar/Services/MessageBarInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Represents a message bar instance used with the <see cref="IMessageBarService"/>.
/// Represents a message bar instance used with the <see cref="INotificationService"/>.
/// </summary>
public class MessageBarInstance : IMessageBarInstance, IDisposable
{
Expand All @@ -18,16 +18,16 @@ public class MessageBarInstance : IMessageBarInstance, IDisposable
private bool _disposed;

/// <summary />
internal MessageBarInstance(IMessageBarService messageBarService, MessageBarOptions options)
: this(messageBarService, componentType: null, options)
internal MessageBarInstance(INotificationService notificationService, MessageBarOptions options)
: this(notificationService, componentType: null, options)
{
}

/// <summary />
internal MessageBarInstance(IMessageBarService messageBarService, Type? componentType, MessageBarOptions options)
internal MessageBarInstance(INotificationService notificationService, Type? componentType, MessageBarOptions options)
{
Options = options;
MessageBarService = messageBarService;
NotificationService = notificationService;
_componentType = componentType;
Id = string.IsNullOrEmpty(options.Id) ? Identifier.NewId() : options.Id;
Index = Interlocked.Increment(ref _counter);
Expand All @@ -37,7 +37,7 @@ internal MessageBarInstance(IMessageBarService messageBarService, Type? componen
Type? IMessageBarInstance.ComponentType => _componentType;

/// <summary />
internal IMessageBarService MessageBarService { get; }
internal INotificationService NotificationService { get; }

/// <summary>
/// Gets the cancellation token used to cancel the auto-dismiss timer when the message bar
Expand All @@ -63,13 +63,13 @@ internal MessageBarInstance(IMessageBarService messageBarService, Type? componen
/// <inheritdoc cref="IMessageBarInstance.CloseAsync()"/>
public Task CloseAsync()
{
return MessageBarService.CloseAsync(this);
return NotificationService.CloseAsync(this);
}

/// <inheritdoc cref="IMessageBarInstance.CloseAsync(MessageBarResult)"/>
public Task CloseAsync(MessageBarResult result)
{
return MessageBarService.CloseAsync(this, result);
return NotificationService.CloseAsync(this, result);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Options for configuring a message bar displayed by the <see cref="IMessageBarService"/>.
/// Options for configuring a message bar displayed by the <see cref="INotificationService"/>.
/// </summary>
public class MessageBarOptions : IFluentComponentBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Represents the result of a message bar managed by the <see cref="IMessageBarService"/>.
/// Represents the result of a message bar managed by the <see cref="INotificationService"/>.
/// </summary>
public class MessageBarResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
namespace Microsoft.FluentUI.AspNetCore.Components;

/// <summary>
/// Subscriber-management portion of the <see cref="MessageBarService"/>.
/// Subscriber-management portion of the <see cref="NotificationService"/>.
/// Allows multiple <see cref="FluentMessageBarProvider"/> instances to receive
/// update notifications from the same service (e.g. when scoped by Section).
/// </summary>
public partial class MessageBarService
public partial class NotificationService
{
private readonly ConcurrentDictionary<string, Func<IMessageBarInstance, Task>> _subscribers = new(StringComparer.Ordinal);

Expand Down
Loading
Loading