Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useful services to IToolbarConfigurationContext and MenuConfigurationContext #4017

Closed
hikalkan opened this issue May 20, 2020 · 0 comments · Fixed by #4032
Closed

Add useful services to IToolbarConfigurationContext and MenuConfigurationContext #4017

hikalkan opened this issue May 20, 2020 · 0 comments · Fixed by #4032

Comments

@hikalkan
Copy link
Member

There are some common operations, like checking permissions and localizing strings, are frequently done in these kind of contributors.
We can design shortcuts on these contexts.

Example:

public class ChatToolbarContributor : IToolbarContributor
{
    public async Task ConfigureToolbarAsync(IToolbarConfigurationContext context)
    {
        if (context.Toolbar.Name == StandardToolbars.Main)
        {
            var authorizationService = context.ServiceProvider
                .GetRequiredService<IAuthorizationService>();

            if (await authorizationService.IsGrantedAsync(ChatPermissions.Messaging))
            {
                context.Toolbar.Items
                    .Insert(0, new ToolbarItem(typeof(MessagesToolbarItemViewComponent)));
            }
        }
    }
}

Can be written easier if we have a context.IsGrantedAsync method. We should resolve these services as lazy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants