Skip to content

Commit 5e79f24

Browse files
authored
Merge pull request #6535 from erikjanwestendorp/update-using-ioc
Porting old Umbraco API Controller [IoC and Dependency injection]
2 parents da3c6bd + d25dbec commit 5e79f24

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

14/umbraco-cms/reference/using-ioc.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,17 @@ Once you have registered the dependencies inject them into your project where ne
223223

224224
If you need to inject your service into a controller or another service, you will do so through the class.
225225

226-
{% hint style="warning" %}
227-
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
228-
{% endhint %}
229-
230226
{% code title="FooController.cs" %}
231227

232228
```csharp
233229
using IOCDocs.Services;
234-
using Umbraco.Cms.Web.Common.Controllers;
230+
using Microsoft.AspNetCore.Mvc;
235231

236232
namespace IOCDocs.Controllers;
237233

238-
public class FooController : UmbracoApiController
234+
[ApiController]
235+
[Route("/umbraco/api/foo")]
236+
public class FooController : Controller
239237
{
240238
private readonly IFooBar _fooBar;
241239

@@ -244,6 +242,7 @@ public class FooController : UmbracoApiController
244242
_fooBar = fooBar;
245243
}
246244

245+
[HttpGet("foo")]
247246
public string Foo()
248247
{
249248
var bar = _fooBar.Foo();

15/umbraco-cms/reference/using-ioc.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,17 @@ Once you have registered the dependencies inject them into your project where ne
223223

224224
If you need to inject your service into a controller or another service, you will do so through the class.
225225

226-
{% hint style="warning" %}
227-
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
228-
{% endhint %}
229-
230226
{% code title="FooController.cs" %}
231227

232228
```csharp
233229
using IOCDocs.Services;
234-
using Umbraco.Cms.Web.Common.Controllers;
230+
using Microsoft.AspNetCore.Mvc;
235231

236232
namespace IOCDocs.Controllers;
237233

238-
public class FooController : UmbracoApiController
234+
[ApiController]
235+
[Route("/umbraco/api/foo")]
236+
public class FooController : Controller
239237
{
240238
private readonly IFooBar _fooBar;
241239

@@ -244,6 +242,7 @@ public class FooController : UmbracoApiController
244242
_fooBar = fooBar;
245243
}
246244

245+
[HttpGet("foo")]
247246
public string Foo()
248247
{
249248
var bar = _fooBar.Foo();

0 commit comments

Comments
 (0)