Skip to content

Commit

Permalink
Add FactoryMethod.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Feb 12, 2024
1 parent 7973a53 commit f28540f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Creational/DesignPatterns.FactoryMethod/AzureStorageDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Azure.Storage.Blobs;

namespace DesignPatterns.FactoryMethod;

public class AzureStorageDownloader : IFileDownloader
{
private readonly BlobContainerClient containerClient;

public AzureStorageDownloader(string connectionString, string containerName)
{
this.containerClient = new BlobContainerClient(connectionString, containerName);
}

public void DownloadFile(string fileName, string destinationPath)
{
BlobClient blobClient = this.containerClient.GetBlobClient(fileName);
blobClient.DownloadTo(destinationPath);
}
}
23 changes: 23 additions & 0 deletions Creational/DesignPatterns.FactoryMethod/AzureStorageFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace DesignPatterns.FactoryMethod;

public class AzureStorageFactory : IStorageServiceFactory
{
private readonly string connectionString;
private readonly string containerName;

public AzureStorageFactory(string connectionString, string containerName)
{
this.connectionString = connectionString;
this.containerName = containerName;
}

public IFileUploader CreateUploader()
{
return new AzureStorageUploader(this.connectionString, this.containerName);
}

public IFileDownloader CreateDownloader()
{
return new AzureStorageDownloader(this.connectionString, this.containerName);
}
}
20 changes: 20 additions & 0 deletions Creational/DesignPatterns.FactoryMethod/AzureStorageUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Azure.Storage.Blobs;

namespace DesignPatterns.FactoryMethod;

public class AzureStorageUploader : IFileUploader
{
private readonly BlobContainerClient containerClient;

public AzureStorageUploader(string connectionString, string containerName)
{
this.containerClient = new BlobContainerClient(connectionString, containerName);
}

public void UploadFile(string filePath)
{
var fileName = Path.GetFileName(filePath);
var blobClient = this.containerClient.GetBlobClient(fileName);
blobClient.Upload(filePath, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.17.1" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Creational/DesignPatterns.FactoryMethod/IFileDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DesignPatterns.FactoryMethod;

public interface IFileDownloader
{
void DownloadFile(string fileName, string destinationPath);
}
6 changes: 6 additions & 0 deletions Creational/DesignPatterns.FactoryMethod/IFileUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DesignPatterns.FactoryMethod;

public interface IFileUploader
{
void UploadFile(string filePath);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DesignPatterns.FactoryMethod;

public interface IStorageServiceFactory
{
IFileUploader CreateUploader();
IFileDownloader CreateDownloader();
}
7 changes: 7 additions & 0 deletions DesignPatterns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Singleton",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.Singleton.UnitTests", "Creational\DesignPatterns.Singleton.UnitTests\DesignPatterns.Singleton.UnitTests.csproj", "{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.FactoryMethod", "Creational\DesignPatterns.FactoryMethod\DesignPatterns.FactoryMethod.csproj", "{DAE417C1-F239-4514-9689-6466F0B52A99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,6 +56,10 @@ Global
{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6}.Release|Any CPU.Build.0 = Release|Any CPU
{DAE417C1-F239-4514-9689-6466F0B52A99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAE417C1-F239-4514-9689-6466F0B52A99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAE417C1-F239-4514-9689-6466F0B52A99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAE417C1-F239-4514-9689-6466F0B52A99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}
Expand All @@ -63,5 +69,6 @@ Global
{FA3C4F09-104E-4F7D-9ADB-E7F22917ADF7} = {5961ADCC-5FA6-4076-A9F4-C1D3207ABE1A}
{658DB1C6-AC85-4E03-99C4-C79116E558F5} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901}
{FFB0861F-5182-40CA-BD19-33BCB0FBA4F6} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901}
{DAE417C1-F239-4514-9689-6466F0B52A99} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901}
EndGlobalSection
EndGlobal

0 comments on commit f28540f

Please sign in to comment.