2018-10-26 15:06:53 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
2018-11-24 15:38:00 +01:00
|
|
|
|
using Umbraco.Core.IO.MediaPathSchemes;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Composing.Composers
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class FileSystemsComposer
|
|
|
|
|
|
{
|
2018-10-26 15:06:53 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* HOW TO REPLACE THE MEDIA UNDERLYING FILESYSTEM
|
|
|
|
|
|
* ----------------------------------------------
|
|
|
|
|
|
*
|
|
|
|
|
|
* Create a component and use it to modify the composition by adding something like:
|
|
|
|
|
|
*
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* composition.Container.RegisterFileSystem<IMediaFileSystem, MediaFileSystem>(
|
|
|
|
|
|
* factory => new PhysicalFileSystem("~/somewhere"));
|
2018-10-26 15:06:53 +02:00
|
|
|
|
*
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* return whatever supporting filesystem you like.
|
2018-10-26 15:06:53 +02:00
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* HOW TO IMPLEMENT MY OWN FILESYSTEM
|
|
|
|
|
|
* ----------------------------------
|
|
|
|
|
|
*
|
|
|
|
|
|
* Create your filesystem class:
|
|
|
|
|
|
*
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* public class MyFileSystem : FileSystemWrapper
|
2018-10-26 15:06:53 +02:00
|
|
|
|
* {
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* public MyFileSystem(IFileSystem innerFileSystem)
|
2018-10-26 15:06:53 +02:00
|
|
|
|
* : base(innerFileSystem)
|
|
|
|
|
|
* { }
|
|
|
|
|
|
* }
|
|
|
|
|
|
*
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* The ctor can have more parameters that will be resolved by the container.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Register your filesystem, in a component:
|
|
|
|
|
|
*
|
|
|
|
|
|
* composition.Container.RegisterFileSystem<MyFileSystem>(
|
|
|
|
|
|
* factory => new PhysicalFileSystem("~/my"));
|
|
|
|
|
|
*
|
|
|
|
|
|
* And that's it, you can inject MyFileSystem wherever it's needed.
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* You can also declare a filesystem interface:
|
|
|
|
|
|
*
|
|
|
|
|
|
* public interface IMyFileSystem : IFileSystem
|
|
|
|
|
|
* { }
|
|
|
|
|
|
*
|
|
|
|
|
|
* Make the class implement the interface, then
|
|
|
|
|
|
* register your filesystem, in a component:
|
2018-10-26 15:06:53 +02:00
|
|
|
|
*
|
2018-11-24 15:38:00 +01:00
|
|
|
|
* composition.Container.RegisterFileSystem<IMyFileSystem, MyFileSystem>(
|
|
|
|
|
|
* factory => new PhysicalFileSystem("~/my"));
|
2018-10-26 15:06:53 +02:00
|
|
|
|
*
|
|
|
|
|
|
* And that's it, you can inject IMyFileSystem wherever it's needed.
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
* WHAT IS SHADOWING
|
|
|
|
|
|
* -----------------
|
|
|
|
|
|
*
|
|
|
|
|
|
* Shadowing is the technology used for Deploy to implement some sort of
|
|
|
|
|
|
* transaction-management on top of filesystems. The plumbing explained above,
|
|
|
|
|
|
* compared to creating your own physical filesystem, ensures that your filesystem
|
|
|
|
|
|
* would participate into such transactions.
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-07-20 15:45:01 +02:00
|
|
|
|
public static IContainer ComposeFileSystems(this IContainer container)
|
2018-07-20 09:49:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
// register FileSystems, which manages all filesystems
|
2018-10-26 15:06:53 +02:00
|
|
|
|
// it needs to be registered (not only the interface) because it provides additional
|
|
|
|
|
|
// functionality eg for scoping, and is injected in the scope provider - whereas the
|
|
|
|
|
|
// interface is really for end-users to get access to filesystems.
|
2018-11-24 16:41:27 +01:00
|
|
|
|
container.RegisterSingleton(factory => factory.CreateInstance<FileSystems>(container));
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
// register IFileSystems, which gives access too all filesystems
|
2018-07-20 15:45:01 +02:00
|
|
|
|
container.RegisterSingleton<IFileSystems>(factory => factory.GetInstance<FileSystems>());
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
2018-11-24 15:38:00 +01:00
|
|
|
|
// register the scheme for media paths
|
|
|
|
|
|
container.RegisterSingleton<IMediaPathScheme, TwoGuidsMediaPathScheme>();
|
2018-10-26 15:06:53 +02:00
|
|
|
|
|
2018-11-24 15:38:00 +01:00
|
|
|
|
// register the IMediaFileSystem implementation with a supporting filesystem
|
|
|
|
|
|
container.RegisterFileSystem<IMediaFileSystem, MediaFileSystem>(
|
|
|
|
|
|
factory => new PhysicalFileSystem("~/media"));
|
2018-10-26 15:06:53 +02:00
|
|
|
|
|
2018-11-24 15:38:00 +01:00
|
|
|
|
return container;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|