Skip to content

Commit 9bbf51d

Browse files
author
Joel Mitchell
committed
Added auto-registration of dependencies and option to override this
1 parent b437e49 commit 9bbf51d

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

src/Cofoundry.Plugins.Azure/AzureBlobFileServiceSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace Cofoundry.Plugins.Azure
99
{
1010
public class AzureBlobFileServiceSettings : PluginConfigurationSettingsBase
1111
{
12+
/// <summary>
13+
/// The connection string to use when accessing files in blob storage
14+
/// </summary>
1215
public string ConnectionString { get; set; }
1316
}
1417
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Cofoundry.Core.Configuration;
2+
using Cofoundry.Core.DependencyInjection;
3+
using Cofoundry.Domain.Data;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Cofoundry.Plugins.Azure
11+
{
12+
public class AzureDependencyRegistration : IDependencyRegistration
13+
{
14+
public void Register(IContainerRegister container)
15+
{
16+
if (AutoBootstrapServices())
17+
{
18+
var delayedRegistrationOptions = new RegistrationOptions()
19+
{
20+
ReplaceExisting = true,
21+
InstanceScope = InstanceScope.PerWebRequest
22+
};
23+
24+
container
25+
.RegisterFactory<AzureBlobFileServiceSettings, ConfigurationSettingsFactory<AzureBlobFileServiceSettings>>()
26+
.RegisterFactory<AzureSettings, ConfigurationSettingsFactory<AzureSettings>>()
27+
.RegisterType<IFileStoreService, AzureBlobFileService>(delayedRegistrationOptions)
28+
;
29+
}
30+
}
31+
32+
/// <summary>
33+
/// Indicates whether we want to auto-bootstrap azure services and run against
34+
/// the azure infrastructure. Disable this in dev when you want to test locally.
35+
/// </summary>
36+
/// <remarks>
37+
/// Publicly exposed setting so it can be used in other Azure dependency registrations.
38+
/// </remarks>
39+
public static bool AutoBootstrapServices()
40+
{
41+
return ConfigurationHelper.GetSettingAsBool("Cofoundry:Plugin:Azure:AutoRegisterDependencies", true);
42+
}
43+
}
44+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Cofoundry.Core.Configuration;
7+
8+
namespace Cofoundry.Plugins.Azure
9+
{
10+
public class AzureSettings : PluginConfigurationSettingsBase
11+
{
12+
public AzureSettings()
13+
{
14+
AutoRegisterDependencies = true;
15+
}
16+
17+
/// <summary>
18+
/// Defaults to true. Indicates whether we want to auto-bootstrap azure services and run against the
19+
/// azure infrastructure. Disable this in dev when you want to test locally.
20+
/// </summary>
21+
public bool AutoRegisterDependencies { get; set; }
22+
}
23+
}

src/Cofoundry.Plugins.Azure/Cofoundry.Plugins.Azure.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
<Private>True</Private>
3939
</Reference>
4040
<Reference Include="Cofoundry.Core, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Cofoundry.Core.0.1.0-beta0017\lib\net461\Cofoundry.Core.dll</HintPath>
41+
<HintPath>..\packages\Cofoundry.Core.0.1.0-beta0018\lib\net461\Cofoundry.Core.dll</HintPath>
4242
<Private>True</Private>
4343
</Reference>
4444
<Reference Include="Cofoundry.Domain, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
45-
<HintPath>..\packages\Cofoundry.Domain.0.1.0-beta0017\lib\net461\Cofoundry.Domain.dll</HintPath>
45+
<HintPath>..\packages\Cofoundry.Domain.0.1.0-beta0018\lib\net461\Cofoundry.Domain.dll</HintPath>
4646
<Private>True</Private>
4747
</Reference>
4848
<Reference Include="Conditions, Version=2.1.0.24, Culture=neutral, processorArchitecture=MSIL">
@@ -136,7 +136,9 @@
136136
<Link>Properties\SolutionInfo.cs</Link>
137137
</Compile>
138138
<Compile Include="AzureBlobFileService.cs" />
139+
<Compile Include="AzureSettings.cs" />
139140
<Compile Include="AzureBlobFileServiceSettings.cs" />
141+
<Compile Include="AzureDependencyRegistration.cs" />
140142
<Compile Include="Properties\AssemblyInfo.cs" />
141143
</ItemGroup>
142144
<ItemGroup>

src/Cofoundry.Plugins.Azure/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="AutoMapper" version="5.1.1" targetFramework="net461" />
4-
<package id="Cofoundry.Core" version="0.1.0-beta0017" targetFramework="net461" />
5-
<package id="Cofoundry.Domain" version="0.1.0-beta0017" targetFramework="net461" />
4+
<package id="Cofoundry.Core" version="0.1.0-beta0018" targetFramework="net461" />
5+
<package id="Cofoundry.Domain" version="0.1.0-beta0018" targetFramework="net461" />
66
<package id="Conditions" version="2.1.0" targetFramework="net461" />
77
<package id="EntityFramework" version="6.1.3" targetFramework="net461" />
88
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" />

0 commit comments

Comments
 (0)