Skip to content

Commit 4cd0544

Browse files
Create an extension methods to easily append to CollectionBuilders (#11691)
* Create UmbracoBuilder.ContentApps.cs Add an extension method to register content apps to make it possible to register content apps in the startup.cs class. * Create UmbracoBuilder.CollectionsBuilders * White space * Rename OEmbedProvider to EmbedProvider * Rename EmbedProvider to OEmbedProvider
1 parent 004d341 commit 4cd0544

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using Umbraco.Cms.Core.Composing;
2+
using Umbraco.Cms.Core.Dashboards;
3+
using Umbraco.Cms.Core.Media;
4+
using Umbraco.Cms.Core.Models.ContentEditing;
5+
using Umbraco.Cms.Core.Routing;
6+
using Umbraco.Cms.Core.Sections;
7+
8+
namespace Umbraco.Cms.Core.DependencyInjection
9+
{
10+
/// <summary>
11+
/// Contains extensions methods for <see cref="IUmbracoBuilder"/> used for registering content apps.
12+
/// </summary>
13+
public static partial class UmbracoBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Register a component.
17+
/// </summary>
18+
/// <typeparam name="T">The type of the component.</typeparam>
19+
/// <param name="builder">The builder.</param>
20+
public static IUmbracoBuilder AddComponent<T>(this IUmbracoBuilder builder)
21+
where T : class, IComponent
22+
{
23+
builder.Components().Append<T>();
24+
return builder;
25+
}
26+
27+
/// <summary>
28+
/// Register a content app.
29+
/// </summary>
30+
/// <typeparam name="T">The type of the content app.</typeparam>
31+
/// <param name="builder">The builder.</param>
32+
public static IUmbracoBuilder AddContentApp<T>(this IUmbracoBuilder builder)
33+
where T : class, IContentAppFactory
34+
{
35+
builder.ContentApps().Append<T>();
36+
return builder;
37+
}
38+
39+
/// <summary>
40+
/// Register a content finder.
41+
/// </summary>
42+
/// <typeparam name="T">The type of the content finder.</typeparam>
43+
/// <param name="builder">The builder.</param>
44+
public static IUmbracoBuilder AddContentFinder<T>(this IUmbracoBuilder builder)
45+
where T : class, IContentFinder
46+
{
47+
builder.ContentFinders().Append<T>();
48+
return builder;
49+
}
50+
51+
/// <summary>
52+
/// Register a dashboard.
53+
/// </summary>
54+
/// <typeparam name="T">The type of the dashboard.</typeparam>
55+
/// <param name="builder">The builder.</param>
56+
public static IUmbracoBuilder AddDashboard<T>(this IUmbracoBuilder builder)
57+
where T : class, IDashboard
58+
{
59+
builder.Dashboards().Add<T>();
60+
return builder;
61+
}
62+
63+
/// <summary>
64+
/// Register a media url provider.
65+
/// </summary>
66+
/// <typeparam name="T">The type of the media url provider.</typeparam>
67+
/// <param name="builder">The builder.</param>
68+
public static IUmbracoBuilder AddMediaUrlProvider<T>(this IUmbracoBuilder builder)
69+
where T : class, IMediaUrlProvider
70+
{
71+
builder.MediaUrlProviders().Append<T>();
72+
return builder;
73+
}
74+
75+
/// <summary>
76+
/// Register a embed provider.
77+
/// </summary>
78+
/// <typeparam name="T">The type of the embed provider.</typeparam>
79+
/// <param name="builder">The builder.</param>
80+
public static IUmbracoBuilder AddOEmbedProvider<T>(this IUmbracoBuilder builder)
81+
where T : class, IEmbedProvider
82+
{
83+
builder.OEmbedProviders().Append<T>();
84+
return builder;
85+
}
86+
87+
/// <summary>
88+
/// Register a section.
89+
/// </summary>
90+
/// <typeparam name="T">The type of the section.</typeparam>
91+
/// <param name="builder">The builder.</param>
92+
public static IUmbracoBuilder AddSection<T>(this IUmbracoBuilder builder)
93+
where T : class, ISection
94+
{
95+
builder.Sections().Append<T>();
96+
return builder;
97+
}
98+
99+
/// <summary>
100+
/// Register a url provider.
101+
/// </summary>
102+
/// <typeparam name="T">The type of the url provider.</typeparam>
103+
/// <param name="builder">The Builder.</param>
104+
public static IUmbracoBuilder AddUrlProvider<T>(this IUmbracoBuilder builder)
105+
where T : class, IUrlProvider
106+
{
107+
builder.UrlProviders().Append<T>();
108+
return builder;
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)