4

The OWIN AppBuilder "UseStatic" bits deliver files from a local filesystem which is handy for some situations, but I would like to instead have it deliver content from an in-memory IDictionary that I pre-populated at application startup. Can anyone point me in a good direction to investigate overriding/changing the behavior?

Thanks.

Snowy
  • 5,942
  • 19
  • 65
  • 119
  • 2
    I think you can achieve this by implementing the IFileSystem interface with your custom implementation and plug it into the StaticFileOptions.FileSystem property. Note: Static file middle ware is still in a pre release stage. There may be bugs in it. – Praburaj Sep 30 '13 at 04:23
  • Why would you want to change a system designed to serve files to serve in-memory data? Seems complicated. Why don't you write a middleware of your own specifically designed to do that. – meilke Sep 30 '13 at 10:10
  • 1
    @meilke, I need to host in an environment with no filesystem (eg Azure site), so using dusk directly is not an option. I was trying to think though an interface based way to have something that will work on systems with accessible physical disk and systems without, and through runtime config make a change. Thanks. – Snowy Sep 30 '13 at 20:42

1 Answers1

2

You'll want to implement your own IFileSystem and IFileInfo classes. An example of this can be seen in the dev branch on CodePlex under src/Microsoft.Owin.FileSystems/EmbeddedResourceFileSystem.cs. This was a community contribution based on this project.

Once implemented you would use it like so

public class InMemoryFileSystem : IFileSystem
{
    public InMemoryFileSystem(IDictionary<string, object> files)
    {}
}

var files = LoadFilesIntoDictionary();

app.UseStaticFiles(options => {
    options.WithFileSystem(new InMemoryFileSystem(files));
});
Brian Surowiec
  • 17,123
  • 8
  • 41
  • 64