Wednesday, August 21, 2019

How do I hand an IFormFile from the UI to infrastructure in onion architecture?

Open the .csproj file for your UI in Notepad. The TargetFramework XML tag (inside the PropertyGroup XML tag inside the Project XML tag wrapping everything) will denote which version of .NET Core you are using and you will want to mimic this version when installing .NET to another project in your solution in lieu of just grabbing the latest. Install .NET Core with this NuGet command:

install-package Microsoft.AspNetCore MyApp.Infrastructure -Version 2.1

 
 

The big problem with this is that in your core project you will also have to have an interface that understands IFormFile however, so maybe we don't want to go there after all. Let's undo:

uninstall-package Microsoft.AspNetCore MyApp.Infrastructure -Version 2.1

 
 

The better thing to do is probably to do just enough work in the UI to turn the IFormFile into a byte[] type bytes array to mimic what is here just enough to get the fileContent variable but not enough to actually write records with it. Defer the writing of a file to the infrastructure. Hand in the bytes array to the infrastructure.

No comments:

Post a Comment