// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.StaticFiles.Infrastructure
{
///
/// Options common to several middleware components
///
/// The type of the subclass
public abstract class SharedOptionsBase
{
///
/// Creates an new instance of the SharedOptionsBase.
///
///
protected SharedOptionsBase(SharedOptions sharedOptions)
{
if (sharedOptions == null)
{
throw new ArgumentNullException(nameof(sharedOptions));
}
SharedOptions = sharedOptions;
}
///
/// Options common to several middleware components
///
protected SharedOptions SharedOptions { get; private set; }
///
/// The relative request path that maps to static resources.
///
public PathString RequestPath
{
get { return SharedOptions.RequestPath; }
set { SharedOptions.RequestPath = value; }
}
///
/// The file system used to locate resources
///
public IFileProvider FileProvider
{
get { return SharedOptions.FileProvider; }
set { SharedOptions.FileProvider = value; }
}
internal void ResolveFileProvider(IHostingEnvironment hostingEnv)
{
if (FileProvider == null)
{
FileProvider = hostingEnv.WebRootFileProvider;
if (FileProvider == null)
{
throw new InvalidOperationException("Missing FileProvider.");
}
}
}
}
}