From 2572d8c459cac6228d1fbd9ce41013762d6ad69a Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Mon, 15 Jan 2024 15:36:26 +1100 Subject: [PATCH] Update to not use static `Instance` --- TalentBlazor/Configure.AppHost.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/TalentBlazor/Configure.AppHost.cs b/TalentBlazor/Configure.AppHost.cs index c01dd3c..98e6be5 100644 --- a/TalentBlazor/Configure.AppHost.cs +++ b/TalentBlazor/Configure.AppHost.cs @@ -26,6 +26,19 @@ public void Configure(IWebHostBuilder builder) => builder "http://localhost:5000", "https://localhost:5001", }, allowCredentials: true)); + var wwwrootVfs = new FileSystemVirtualFiles(context.HostingEnvironment.WebRootPath); + var appDataVfs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath.CombineWith("App_Data").AssertDir()); + services.AddPlugin(new FilesUploadFeature( + new UploadLocation("profiles", wwwrootVfs, allowExtensions:FileExt.WebImages, + resolvePath: ctx => $"/profiles/{ctx.FileName}"), + new UploadLocation("users", wwwrootVfs, allowExtensions:FileExt.WebImages, + resolvePath: ctx => $"/profiles/users/{ctx.UserAuthId}.{ctx.FileExtension}"), + new UploadLocation("applications", appDataVfs, maxFileCount: 3, maxFileBytes: 10_000_000, + resolvePath: ctx => ctx.GetLocationPath((ctx.Dto is CreateJobApplication create + ? $"jobapp/{create.JobId}/{create.ContactId}/{ctx.FileName}" + : $"app/{ctx.Dto.GetId()}") + $"/{ctx.DateSegment}/{ctx.FileName}"), + readAccessRole: RoleNames.AllowAnon, writeAccessRole: RoleNames.AllowAnon) + )); }); public AppHost() : base("TalentBlazor", typeof(MyServices).Assembly) { } @@ -38,19 +51,7 @@ public override void Configure(Container container) AdminAuthSecret = "secretz", }); - var wwwrootVfs = GetVirtualFileSource(); - var appDataVfs = new FileSystemVirtualFiles(ContentRootDirectory.RealPath.CombineWith("App_Data").AssertDir()); - Instance.Plugins.Add(new FilesUploadFeature( - new UploadLocation("profiles", wwwrootVfs, allowExtensions:FileExt.WebImages, - resolvePath: ctx => $"/profiles/{ctx.FileName}"), - new UploadLocation("users", wwwrootVfs, allowExtensions:FileExt.WebImages, - resolvePath: ctx => $"/profiles/users/{ctx.UserAuthId}.{ctx.FileExtension}"), - new UploadLocation("applications", appDataVfs, maxFileCount: 3, maxFileBytes: 10_000_000, - resolvePath: ctx => ctx.GetLocationPath((ctx.Dto is CreateJobApplication create - ? $"jobapp/{create.JobId}/{create.ContactId}/{ctx.FileName}" - : $"app/{ctx.Dto.GetId()}") + $"/{ctx.DateSegment}/{ctx.FileName}"), - readAccessRole: RoleNames.AllowAnon, writeAccessRole: RoleNames.AllowAnon) - )); + } }