-
Hello!
It's the same codebase and model from the issue #1680. My public class Startup
{
private readonly IConfiguration _config;
public Startup(IConfiguration configuration)
{
_config = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddPiranha();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApi api)
{
App.Init(api);
app.UseEndpoints(endpoints => endpoints.MapControllers());
}
} My controller logic public class MyController : Controller
{
public MyController(IApi api, IModelLoader modelLoader, IApplicationService service, IDb db)
{
_api = api;
_db = db;
_service = service;
_modelLoader = modelLoader;
}
[HttpGet]
public async Task<IActionResult> GetAsync()
{
foreach (Guid pageId in _db.Pages
.Where(p => p.Published <= DateTime.Now
&& p.PageTypeId == "MyPage")
.Select(p => p.Id)
.ToList())
{
// I've tried using the IApi (same error occurs)
//MyPage page =
// await _api.Pages
// .GetByIdAsync<MyPage>(pageId)
// .ConfigureAwait(false);
// I've tried using the IApplicationService (same error occurs)
//MyPage page =
// await _service.Api.Pages
// .GetByIdAsync<MyPage>(pageId)
// .ConfigureAwait(false);
// I've tried using the IModelLoader (same error occurs)
MyPage page =
await _modelLoader
.GetPageAsync<MyPage>(pageId, null, false)
.ConfigureAwait(false);
}
}
} I'm using Piranha's packages with the following versions:
More info:
Am I missing something about the implementation of Piranha's API to fetch complex and dynamic models? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solved! Indeed, I was forgetting something. At public void ConfigureServices(IServiceCollection services)
{
services.AddPiranha(options =>
{
options.UseFileStorage(baseUrl: "https://example.org/files/");
}
} Packages reference.
|
Beta Was this translation helpful? Give feedback.
Solved! Indeed, I was forgetting something.
While fetching the
GetPublicUrl
for a image model, the service was looking for anIStorage
service.None was found, so a Null Exception was being thrown.
Since the API doesn't save files, adding the package
Piranha.Local.FileStorage
and using a FileStorage with only a baseUrl solved the issue.At
startup.cs
Packages reference.