diff --git a/Egineering.UrlShortener.Services/Egineering.UrlShortener.Services.csproj b/Egineering.UrlShortener.Services/Egineering.UrlShortener.Services.csproj
index 0b14f15..72407ef 100644
--- a/Egineering.UrlShortener.Services/Egineering.UrlShortener.Services.csproj
+++ b/Egineering.UrlShortener.Services/Egineering.UrlShortener.Services.csproj
@@ -13,4 +13,8 @@
+
+
+
+
diff --git a/Egineering.UrlShortener.Services/GlobalUsings.cs b/Egineering.UrlShortener.Services/GlobalUsings.cs
index 140eb3b..35b5600 100644
--- a/Egineering.UrlShortener.Services/GlobalUsings.cs
+++ b/Egineering.UrlShortener.Services/GlobalUsings.cs
@@ -1,7 +1,7 @@
global using System.Diagnostics.CodeAnalysis;
-global using Azure;
-global using Azure.Data.Tables;
-global using Egineering.UrlShortener.Services.DTOs;
-global using Egineering.UrlShortener.Services.Helpers;
+//global using Azure;
+//global using Azure.Data.Tables;
+//global using Egineering.UrlShortener.Services.DTOs;
+//global using Egineering.UrlShortener.Services.Helpers;
global using Egineering.UrlShortener.Services.Interfaces;
global using Microsoft.Extensions.Configuration;
diff --git a/Egineering.UrlShortener.Services/Helpers/Constants.cs b/Egineering.UrlShortener.Services/Helpers/Constants.cs
index 705efb2..af674f6 100644
--- a/Egineering.UrlShortener.Services/Helpers/Constants.cs
+++ b/Egineering.UrlShortener.Services/Helpers/Constants.cs
@@ -1,4 +1,7 @@
-namespace Egineering.UrlShortener.Services.Helpers;
+using System.Diagnostics.Contracts;
+using System.Runtime.CompilerServices;
+
+namespace Egineering.UrlShortener.Services.Helpers;
[ExcludeFromCodeCoverage]
public static class Constants
@@ -6,21 +9,9 @@ public static class Constants
// API
public const string Authorization = "Authorization";
public const string SecurityToken = "SecurityToken";
+ public const string StorageType = "StorageType";
+
+
- // Azure Storage
- public const string AzureStorageConnectionString = "AzureStorage";
- public const string UrlTableName = "urls";
- // URL properties
- public const string Name = "name";
- public const string Url = "url";
- public const string UrlPartitionKey = Url;
- public const string Visits = "visits";
- public const string IsPublic = "isPublic";
-
- // Azure Request Error Codes
- public static class AzureRequestErrorCodes
- {
- public const string ResourceNotFound = "ResourceNotFound";
- }
}
diff --git a/Egineering.UrlShortener.Services/Interfaces/IAzureTableStorageService.cs b/Egineering.UrlShortener.Services/Interfaces/IAzureTableStorageService.cs
deleted file mode 100644
index 261ebd2..0000000
--- a/Egineering.UrlShortener.Services/Interfaces/IAzureTableStorageService.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace Egineering.UrlShortener.Services.Interfaces;
-
-public interface IAzureTableStorageService
-{
- Task GetUrlFromVanityAsync(string vanity);
- IEnumerable GetAllPublicUrls();
- Task AddUrl(UrlRequest urlRequest);
- Task ReplaceUrl(UrlRequest urlRequest);
-}
diff --git a/Egineering.UrlShortener.Services/AzureTableStorageService.cs b/Egineering.UrlShortener.Storage.AzureTableStorage/AzureTableStorageService.cs
similarity index 85%
rename from Egineering.UrlShortener.Services/AzureTableStorageService.cs
rename to Egineering.UrlShortener.Storage.AzureTableStorage/AzureTableStorageService.cs
index 1d46f7a..55bc27e 100644
--- a/Egineering.UrlShortener.Services/AzureTableStorageService.cs
+++ b/Egineering.UrlShortener.Storage.AzureTableStorage/AzureTableStorageService.cs
@@ -1,6 +1,11 @@
-using Egineering.UrlShortener.Services.Exceptions;
-
-namespace Egineering.UrlShortener.Services;
+global using Azure;
+global using Azure.Data.Tables;
+using Egineering.UrlShortener.Storage.AzureTableStorage;
+using Egineering.UrlShortener.Storage.AzureTableStorage.Interfaces;
+using Egineering.UrlShortener.Storage.DTOs;
+using Egineering.UrlShortener.Storage.Exceptions;
+using Microsoft.Extensions.Configuration;
+namespace Egineering.UrlShortener.Services.StorageServices;
public class AzureTableStorageService : IAzureTableStorageService
{
@@ -49,7 +54,7 @@ public IEnumerable GetAllPublicUrls()
var results = tableEntities.Select(entity => new ShortenedUrl
{
Name = entity.GetString(Constants.Name),
- PartitionKey = entity.PartitionKey,
+ //PartitionKey = entity.PartitionKey, //TODO: Remove?
Timestamp = entity.Timestamp.Value,
Url = entity.GetString(Constants.Url),
Vanity = entity.RowKey,
@@ -84,13 +89,13 @@ public async Task AddUrl(UrlRequest urlRequest)
public async Task ReplaceUrl(UrlRequest urlRequest)
{
var urlEntity = await GetUrlEntityByVanity(urlRequest.Vanity);
-
+
if (urlEntity == null)
{
throw new UrlEntityNotFoundException(urlRequest.Vanity);
}
- var entity = new TableEntity(Constants.UrlPartitionKey, urlRequest.Vanity)
+ var entity = new TableEntity(Constants.UrlPartitionKey, urlRequest.Vanity)
{
{ Constants.Name, urlRequest.Name },
{ Constants.Url, urlRequest.Url },
@@ -122,4 +127,7 @@ private TableClient GetUrlTableClient()
}
return tableEntity;
}
+ public static string TypeName => "AzureTableStorage";
+ public bool IsStorageType(string name) => name == TypeName;
+ public string StorageType() => TypeName;
}
diff --git a/Egineering.UrlShortener.Storage.AzureTableStorage/Constants.cs b/Egineering.UrlShortener.Storage.AzureTableStorage/Constants.cs
new file mode 100644
index 0000000..67f9a4c
--- /dev/null
+++ b/Egineering.UrlShortener.Storage.AzureTableStorage/Constants.cs
@@ -0,0 +1,22 @@
+namespace Egineering.UrlShortener.Storage.AzureTableStorage
+{
+ internal static class Constants
+ {
+ // Azure Storage
+ public const string AzureStorageConnectionString = "AzureStorage";
+ public const string UrlTableName = "urls";
+
+ // URL properties
+ public const string Name = "name";
+ public const string Url = "url";
+ public const string UrlPartitionKey = Url;
+ public const string Visits = "visits";
+ public const string IsPublic = "isPublic";
+
+ // Azure Request Error Codes
+ public static class AzureRequestErrorCodes
+ {
+ public const string ResourceNotFound = "ResourceNotFound";
+ }
+ }
+}
diff --git a/Egineering.UrlShortener.Storage.AzureTableStorage/Egineering.UrlShortener.Storage.AzureTableStorage.csproj b/Egineering.UrlShortener.Storage.AzureTableStorage/Egineering.UrlShortener.Storage.AzureTableStorage.csproj
new file mode 100644
index 0000000..4290126
--- /dev/null
+++ b/Egineering.UrlShortener.Storage.AzureTableStorage/Egineering.UrlShortener.Storage.AzureTableStorage.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Egineering.UrlShortener.Storage.AzureTableStorage/Interfaces/IAzureTableStorageService.cs b/Egineering.UrlShortener.Storage.AzureTableStorage/Interfaces/IAzureTableStorageService.cs
new file mode 100644
index 0000000..c34a6d8
--- /dev/null
+++ b/Egineering.UrlShortener.Storage.AzureTableStorage/Interfaces/IAzureTableStorageService.cs
@@ -0,0 +1,13 @@
+using Egineering.UrlShortener.Storage.DTOs;
+using Egineering.UrlShortener.Storage.Interfaces;
+
+namespace Egineering.UrlShortener.Storage.AzureTableStorage.Interfaces;
+
+public interface IAzureTableStorageService : IStorageService
+{
+ Task GetUrlFromVanityAsync(string vanity);
+ //public string PartitionKey { get; set; }
+ IEnumerable GetAllPublicUrls();
+ Task AddUrl(UrlRequest urlRequest);
+ Task ReplaceUrl(UrlRequest urlRequest);
+}
diff --git a/Egineering.UrlShortener.Storage.AzureTableStorage/PluginConfiguration.cs b/Egineering.UrlShortener.Storage.AzureTableStorage/PluginConfiguration.cs
new file mode 100644
index 0000000..e16bfb9
--- /dev/null
+++ b/Egineering.UrlShortener.Storage.AzureTableStorage/PluginConfiguration.cs
@@ -0,0 +1,19 @@
+using Egineering.UrlShortener.Services.StorageServices;
+using Egineering.UrlShortener.Storage.Interfaces;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Egineering.UrlShortener.Storage.AzureTableStorage
+{
+ public class PluginConfiguration : IPluginFactory
+ {
+ public void Configure(IServiceCollection services)
+ {
+ services.AddSingleton();
+ }
+
+ public string StorageType()
+ {
+ return AzureTableStorageService.TypeName;
+ }
+ }
+}
diff --git a/Egineering.UrlShortener.Services/DTOs/ShortenedUrl.cs b/Egineering.UrlShortener.Storage/DTOs/ShortenedUrl.cs
similarity index 75%
rename from Egineering.UrlShortener.Services/DTOs/ShortenedUrl.cs
rename to Egineering.UrlShortener.Storage/DTOs/ShortenedUrl.cs
index d459685..75aa005 100644
--- a/Egineering.UrlShortener.Services/DTOs/ShortenedUrl.cs
+++ b/Egineering.UrlShortener.Storage/DTOs/ShortenedUrl.cs
@@ -1,10 +1,11 @@
-namespace Egineering.UrlShortener.Services.DTOs;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Egineering.UrlShortener.Storage.DTOs;
[ExcludeFromCodeCoverage]
public class ShortenedUrl
{
public string Name { get; set; }
- public string PartitionKey { get; set; }
public DateTimeOffset Timestamp { get; set; }
public string Url { get; set; }
public string Vanity { get; set; }
diff --git a/Egineering.UrlShortener.Services/DTOs/UrlRequest.cs b/Egineering.UrlShortener.Storage/DTOs/UrlRequest.cs
similarity index 69%
rename from Egineering.UrlShortener.Services/DTOs/UrlRequest.cs
rename to Egineering.UrlShortener.Storage/DTOs/UrlRequest.cs
index 3b3a387..08ac170 100644
--- a/Egineering.UrlShortener.Services/DTOs/UrlRequest.cs
+++ b/Egineering.UrlShortener.Storage/DTOs/UrlRequest.cs
@@ -1,4 +1,6 @@
-namespace Egineering.UrlShortener.Services.DTOs;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Egineering.UrlShortener.Storage.DTOs;
[ExcludeFromCodeCoverage]
public class UrlRequest
diff --git a/Egineering.UrlShortener.Storage/Egineering.UrlShortener.Storage.csproj b/Egineering.UrlShortener.Storage/Egineering.UrlShortener.Storage.csproj
new file mode 100644
index 0000000..ee0a12b
--- /dev/null
+++ b/Egineering.UrlShortener.Storage/Egineering.UrlShortener.Storage.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/Egineering.UrlShortener.Services/Exceptions/ConflictException.cs b/Egineering.UrlShortener.Storage/Exceptions/ConflictException.cs
similarity index 65%
rename from Egineering.UrlShortener.Services/Exceptions/ConflictException.cs
rename to Egineering.UrlShortener.Storage/Exceptions/ConflictException.cs
index d67b087..ce28852 100644
--- a/Egineering.UrlShortener.Services/Exceptions/ConflictException.cs
+++ b/Egineering.UrlShortener.Storage/Exceptions/ConflictException.cs
@@ -1,4 +1,6 @@
-namespace Egineering.UrlShortener.Services.Exceptions;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Egineering.UrlShortener.Storage.Exceptions;
[ExcludeFromCodeCoverage]
public class ConflictException : Exception
diff --git a/Egineering.UrlShortener.Services/Exceptions/UnauthorizedException.cs b/Egineering.UrlShortener.Storage/Exceptions/UnauthorizedException.cs
similarity index 62%
rename from Egineering.UrlShortener.Services/Exceptions/UnauthorizedException.cs
rename to Egineering.UrlShortener.Storage/Exceptions/UnauthorizedException.cs
index 5521ed1..84fb6c0 100644
--- a/Egineering.UrlShortener.Services/Exceptions/UnauthorizedException.cs
+++ b/Egineering.UrlShortener.Storage/Exceptions/UnauthorizedException.cs
@@ -1,4 +1,6 @@
-namespace Egineering.UrlShortener.Services.Exceptions;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Egineering.UrlShortener.Storage.Exceptions;
[ExcludeFromCodeCoverage]
public class UnauthorizedException : Exception
diff --git a/Egineering.UrlShortener.Services/Exceptions/UrlEntityNotFoundException.cs b/Egineering.UrlShortener.Storage/Exceptions/UrlEntityNotFoundException.cs
similarity index 67%
rename from Egineering.UrlShortener.Services/Exceptions/UrlEntityNotFoundException.cs
rename to Egineering.UrlShortener.Storage/Exceptions/UrlEntityNotFoundException.cs
index f9d4ca7..db53e39 100644
--- a/Egineering.UrlShortener.Services/Exceptions/UrlEntityNotFoundException.cs
+++ b/Egineering.UrlShortener.Storage/Exceptions/UrlEntityNotFoundException.cs
@@ -1,4 +1,5 @@
-namespace Egineering.UrlShortener.Services.Exceptions;
+using System.Diagnostics.CodeAnalysis;
+namespace Egineering.UrlShortener.Storage.Exceptions;
[ExcludeFromCodeCoverage]
public class UrlEntityNotFoundException : Exception
diff --git a/Egineering.UrlShortener.Storage/Interfaces/IStorageBuilder.cs b/Egineering.UrlShortener.Storage/Interfaces/IStorageBuilder.cs
new file mode 100644
index 0000000..27028a5
--- /dev/null
+++ b/Egineering.UrlShortener.Storage/Interfaces/IStorageBuilder.cs
@@ -0,0 +1,9 @@
+
+namespace Egineering.UrlShortener.Storage.Interfaces
+{
+ public interface IStorageBuilder
+ {
+ Dictionary StorageOptions { get; }
+ Type? FindStorageOption(string name);
+ }
+}
\ No newline at end of file
diff --git a/Egineering.UrlShortener.Storage/Interfaces/IStorageFactory.cs b/Egineering.UrlShortener.Storage/Interfaces/IStorageFactory.cs
new file mode 100644
index 0000000..0a5f8f6
--- /dev/null
+++ b/Egineering.UrlShortener.Storage/Interfaces/IStorageFactory.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Egineering.UrlShortener.Storage.Interfaces
+{
+
+ public interface IPluginFactory
+ {
+ void Configure(IServiceCollection services);
+ string StorageType();
+ }
+}
diff --git a/Egineering.UrlShortener.Storage/Interfaces/IStorageService.cs b/Egineering.UrlShortener.Storage/Interfaces/IStorageService.cs
new file mode 100644
index 0000000..5479bb4
--- /dev/null
+++ b/Egineering.UrlShortener.Storage/Interfaces/IStorageService.cs
@@ -0,0 +1,16 @@
+
+using Egineering.UrlShortener.Storage.DTOs;
+
+namespace Egineering.UrlShortener.Storage.Interfaces
+{
+ public interface IStorageService
+ {
+ bool IsStorageType(string name);
+ string StorageType();
+
+ Task GetUrlFromVanityAsync(string vanity);
+ IEnumerable GetAllPublicUrls();
+ Task AddUrl(UrlRequest urlRequest);
+ Task ReplaceUrl(UrlRequest urlRequest);
+ }
+}
diff --git a/Egineering.UrlShortener.Storage/StorageBuilder.cs b/Egineering.UrlShortener.Storage/StorageBuilder.cs
new file mode 100644
index 0000000..825b806
--- /dev/null
+++ b/Egineering.UrlShortener.Storage/StorageBuilder.cs
@@ -0,0 +1,49 @@
+using Egineering.UrlShortener.Storage.Interfaces;
+using McMaster.NETCore.Plugins;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Egineering.UrlShortener.Services
+{
+ public static class StorageBuilder
+ {
+ static private List LoadtorageOptions()
+ {
+ var loaders = new List();
+
+ // create plugin loaders
+ var pluginsDir = Path.Combine(AppContext.BaseDirectory, "plugins");
+ foreach (var dir in Directory.GetDirectories(pluginsDir))
+ {
+ var dirName = Path.GetFileName(dir);
+ var pluginDll = Path.Combine(dir, dirName + ".dll");
+ if (File.Exists(pluginDll))
+ {
+ var loader = PluginLoader.CreateFromAssemblyFile(
+ pluginDll,
+ sharedTypes: new[] { typeof(IPluginFactory), typeof(IServiceCollection) });
+ loaders.Add(loader);
+ }
+ }
+ return loaders;
+ }
+
+ public static void ConfigureStorageProvider(IServiceCollection services, string storagePluginName)
+ {
+ var loaders = LoadtorageOptions();
+ // Create an instance of plugin types
+ foreach (var loader in loaders)
+ {
+ foreach (var pluginType in loader
+ .LoadDefaultAssembly()
+ .GetTypes()
+ .Where(t => typeof(IPluginFactory).IsAssignableFrom(t) && !t.IsAbstract))
+ {
+ // This assumes the implementation of IPluginFactory has a parameterless constructor
+ var plugin = Activator.CreateInstance(pluginType) as IPluginFactory;
+ if(plugin?.StorageType() == storagePluginName)
+ plugin?.Configure(services);
+ }
+ }
+ }
+ }
+}
diff --git a/Egineering.UrlShortener.sln b/Egineering.UrlShortener.sln
index 8b5a4d2..8738118 100644
--- a/Egineering.UrlShortener.sln
+++ b/Egineering.UrlShortener.sln
@@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Egineering.UrlShortener", "Egineering.UrlShortener\Egineering.UrlShortener.csproj", "{AD04C2A5-7441-4BBC-93C4-309EF3E61E48}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egineering.UrlShortener", "Egineering.UrlShortener\Egineering.UrlShortener.csproj", "{AD04C2A5-7441-4BBC-93C4-309EF3E61E48}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Egineering.UrlShortener.Services", "Egineering.UrlShortener.Services\Egineering.UrlShortener.Services.csproj", "{A7220A97-E567-4421-AC91-7BD60ABB5B5A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egineering.UrlShortener.Services", "Egineering.UrlShortener.Services\Egineering.UrlShortener.Services.csproj", "{A7220A97-E567-4421-AC91-7BD60ABB5B5A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Egineering.UrlShortener.Storage", "Egineering.UrlShortener.Storage\Egineering.UrlShortener.Storage.csproj", "{FDCB7A2D-933E-41D1-B1AA-D6D65197275C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Egineering.UrlShortener.Storage.AzureTableStorage", "Egineering.UrlShortener.Storage.AzureTableStorage\Egineering.UrlShortener.Storage.AzureTableStorage.csproj", "{4400303B-BA66-4D86-9781-E28B5CB7E5DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +25,14 @@ Global
{A7220A97-E567-4421-AC91-7BD60ABB5B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7220A97-E567-4421-AC91-7BD60ABB5B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7220A97-E567-4421-AC91-7BD60ABB5B5A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FDCB7A2D-933E-41D1-B1AA-D6D65197275C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FDCB7A2D-933E-41D1-B1AA-D6D65197275C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FDCB7A2D-933E-41D1-B1AA-D6D65197275C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FDCB7A2D-933E-41D1-B1AA-D6D65197275C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4400303B-BA66-4D86-9781-E28B5CB7E5DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4400303B-BA66-4D86-9781-E28B5CB7E5DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4400303B-BA66-4D86-9781-E28B5CB7E5DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4400303B-BA66-4D86-9781-E28B5CB7E5DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Egineering.UrlShortener/Egineering.UrlShortener.csproj b/Egineering.UrlShortener/Egineering.UrlShortener.csproj
index 77822b9..80cba85 100644
--- a/Egineering.UrlShortener/Egineering.UrlShortener.csproj
+++ b/Egineering.UrlShortener/Egineering.UrlShortener.csproj
@@ -12,10 +12,18 @@
+
+
+ false
+
+
+
+
+
diff --git a/Egineering.UrlShortener/GlobalUsings.cs b/Egineering.UrlShortener/GlobalUsings.cs
index 8182a62..bf0e0b2 100644
--- a/Egineering.UrlShortener/GlobalUsings.cs
+++ b/Egineering.UrlShortener/GlobalUsings.cs
@@ -1,6 +1,6 @@
global using Azure;
global using Egineering.UrlShortener.Services;
-global using Egineering.UrlShortener.Services.DTOs;
-global using Egineering.UrlShortener.Services.Exceptions;
+//global using Egineering.UrlShortener.Services.DTOs;
+global using Egineering.UrlShortener.Storage.Exceptions;
global using Egineering.UrlShortener.Services.Helpers;
global using Egineering.UrlShortener.Services.Interfaces;
diff --git a/Egineering.UrlShortener/Program.cs b/Egineering.UrlShortener/Program.cs
index 0f57ced..d8e6b9a 100644
--- a/Egineering.UrlShortener/Program.cs
+++ b/Egineering.UrlShortener/Program.cs
@@ -1,9 +1,13 @@
+using Egineering.UrlShortener.Storage.DTOs;
+using Egineering.UrlShortener.Storage.Interfaces;
+using Egineering.UrlShortener.Storage.Exceptions;
+using Microsoft.Extensions.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
-AddServices(builder.Services);
+AddServices(builder.Services, builder.Configuration[Constants.StorageType]);
var app = builder.Build();
@@ -22,7 +26,7 @@
await httpContext.Response.SendFileAsync("wwwroot/index.html");
});
-app.MapGet("/{vanity}", async (string vanity, HttpContext httpContext, IAzureTableStorageService service) =>
+app.MapGet("/{vanity}", async (string vanity, HttpContext httpContext, IStorageService service) =>
{
try
{
@@ -37,7 +41,7 @@
}
});
-app.MapGet("/api/urls", async (IAzureTableStorageService service, HttpContext httpContext) =>
+app.MapGet("/api/urls", async (IStorageService service, HttpContext httpContext) =>
{
try
{
@@ -52,7 +56,7 @@
}
});
-app.MapPost("/api/urls", async (UrlRequest urlRequest, IAzureTableStorageService service,
+app.MapPost("/api/urls", async (UrlRequest urlRequest, IStorageService service,
HttpContext httpContext) =>
{
try
@@ -79,7 +83,7 @@
}
});
-app.MapPut("/api/urls", async (UrlRequest urlRequest, IAzureTableStorageService service,
+app.MapPut("/api/urls", async (UrlRequest urlRequest, IStorageService service,
HttpContext httpContext) =>
{
try
@@ -117,9 +121,9 @@
app.Run();
-static void AddServices(IServiceCollection services)
+static void AddServices(IServiceCollection services, string storageType)
{
- services.AddSingleton();
+ StorageBuilder.ConfigureStorageProvider(services, storageType);
services.AddSingleton();
}
diff --git a/Egineering.UrlShortener/appsettings.json b/Egineering.UrlShortener/appsettings.json
index cf6d9cc..55b1d73 100644
--- a/Egineering.UrlShortener/appsettings.json
+++ b/Egineering.UrlShortener/appsettings.json
@@ -9,6 +9,7 @@
"ConnectionStrings": {
"AzureStorage": "#{ConnectionStrings_AzureStorage}"
},
+ "StorageType": "AzureTableStorage",
"SecurityToken": "#{SecurityToken}",
"QRCodeTheme": {
"ImagePath": "#{QRCodeTheme_ImagePath}",