简体   繁体   中英

Run ASP.NET application in Windows Azure AND on a local server

I try to create an application that is able to run in Windows Azure cloud but also on a local server.

Most parts of the application already works on both without problem. But there are some features that I don't know how to make them run on both, for example:

Users are able to upload attachments. In Azure the files are stored in the Windows Azure Storage, on the local server they should be stored in a local folder.

I have no idea how to manage this.

I'd like to suggest you to learn about inversion of control, because you'll be able to switch file storage and other things depending on selected hosting platform.

For example, you'd have an interface called IFileStorage having such methods (and more):

  • Create
  • Append
  • Remove
  • ...

And two implementations for IFileStorage :

  • WinAzureFileStorage
  • DefaultFileStorage

At the end of the day, you'll be doing that:

IFileStorage storage = DependencyManager.Resolve<IFileStorage>();
storage.Create("SomeFile.txt");
storage.Append("SomeFile.txt", "Hello world");

And some inversion of control configuration will map the appropiate IFileStorage implementation depending on hosting platform.

If you want to learn more about inversion of control :

Finally, if you think this is the right way, check Castle Windsor, which is a great, solid and stable inversion of control (and other things) framework on top of .NET:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM