Skip to content

Commit 3c5f6f1

Browse files
committed
Container registrations refactored
Collection name Generation Settings refactored
1 parent 3caddd4 commit 3c5f6f1

File tree

10 files changed

+144
-46
lines changed

10 files changed

+144
-46
lines changed

src/Simplify.Web.Postman/DefaultPostmanGenerationSettingsFactory.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Simplify.Web.Postman/FileCollectionExporter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Simplify.Web.Modules;
33
using Simplify.Web.Postman.Json;
44
using Simplify.Web.Postman.Models;
5+
using Simplify.Web.Postman.Settings;
56

67
namespace Simplify.Web.Postman
78
{
@@ -13,15 +14,15 @@ public class FileCollectionExporter : ICollectionExporter
1314
{
1415
private readonly CollectionModelSerializer _serializer;
1516
private readonly IEnvironment _environment;
16-
private readonly PostmanGenerationSettings _settings;
17+
private readonly IPostmanGenerationSettings _settings;
1718

1819
/// <summary>
1920
/// Initializes a new instance of the <see cref="FileCollectionExporter"/> class.
2021
/// </summary>
2122
/// <param name="serializer">The serializer.</param>
2223
/// <param name="environment">The environment.</param>
2324
/// <param name="settings">The settings.</param>
24-
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, PostmanGenerationSettings settings)
25+
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, IPostmanGenerationSettings settings)
2526
{
2627
_serializer = serializer;
2728
_environment = environment;

src/Simplify.Web.Postman/Models/CollectionHeader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
/// </summary>
66
public class CollectionHeader
77
{
8+
public string Name { get; set; }
89
}
910
}

src/Simplify.Web.Postman/Models/CollectionModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class CollectionModel
1414
/// <value>
1515
/// The header.
1616
/// </value>
17-
public CollectionHeader? Header { get; set; }
17+
[JsonPropertyName("info")]
18+
public CollectionHeader Header { get; set; }
1819

1920
[JsonPropertyName("item")]
2021
public IList<CollectionItem> Items { get; set; } = new List<CollectionItem>();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Simplify.Web.Postman.Models;
2+
using Simplify.Web.Postman.Settings;
3+
4+
namespace Simplify.Web.Postman.PartBuilders
5+
{
6+
public class CollectionHeaderBuilder : ICollectionPartBuilder
7+
{
8+
private readonly IPostmanGenerationSettings _settings;
9+
10+
public CollectionHeaderBuilder(IPostmanGenerationSettings settings)
11+
{
12+
_settings = settings;
13+
}
14+
15+
public void Build(CollectionModel model)
16+
{
17+
model.Header = new CollectionHeader
18+
{
19+
Name = _settings.CollectionName
20+
};
21+
}
22+
}
23+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace Simplify.Web.Postman.Settings
2+
{
3+
/// <summary>
4+
/// Represents postman files generation settings
5+
/// </summary>
6+
public interface IPostmanGenerationSettings
7+
{
8+
/// <summary>
9+
/// Gets or sets the name of the collection.
10+
/// </summary>
11+
/// <value>
12+
/// The name of the collection.
13+
/// </value>
14+
string CollectionName { get; }
15+
16+
/// <summary>
17+
/// Gets or sets the name of the collection file.
18+
/// </summary>
19+
/// <value>
20+
/// The name of the collection file.
21+
/// </value>
22+
string CollectionFileName { get; }
23+
24+
/// <summary>
25+
/// Gets or sets the collection file name postfix.
26+
/// </summary>
27+
/// <value>
28+
/// The collection file name postfix.
29+
/// </value>
30+
string CollectionFileNamePostfix { get; }
31+
32+
/// <summary>
33+
/// Gets or sets the name of the environment file.
34+
/// </summary>
35+
/// <value>
36+
/// The name of the environment file.
37+
/// </value>
38+
string? EnvironmentFileName { get; }
39+
40+
/// <summary>
41+
/// Gets or sets the environment file name postfix.
42+
/// </summary>
43+
/// <value>
44+
/// The environment file name postfix.
45+
/// </value>
46+
string EnvironmentFileNamePostfix { get; }
47+
48+
/// <summary>
49+
/// Gets or sets the generation folder path.
50+
/// </summary>
51+
/// <value>
52+
/// The generation folder path.
53+
/// </value>
54+
string GenerationFolderPath { get; }
55+
}
56+
}

src/Simplify.Web.Postman/PostmanGenerationSettings.cs renamed to src/Simplify.Web.Postman/Settings/PostmanGenerationSettings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace Simplify.Web.Postman
1+
using System.Reflection;
2+
3+
namespace Simplify.Web.Postman.Settings
24
{
35
/// <summary>
46
/// Provides postman files generation settings
57
/// </summary>
6-
public class PostmanGenerationSettings
8+
public class PostmanGenerationSettings : IPostmanGenerationSettings
79
{
810
/// <summary>
911
/// Initializes a new instance of the <see cref="PostmanGenerationSettings"/> class.
@@ -13,8 +15,22 @@ public PostmanGenerationSettings()
1315
GenerationFolderPath = "postman";
1416
CollectionFileNamePostfix = ".postman_collection";
1517
EnvironmentFileNamePostfix = ".postman_environment";
18+
19+
var projectAssemblyName = Assembly.GetEntryAssembly()?.GetName().Name ?? "App";
20+
21+
CollectionName = projectAssemblyName;
22+
CollectionFileName = projectAssemblyName;
23+
EnvironmentFileName = projectAssemblyName;
1624
}
1725

26+
/// <summary>
27+
/// Gets or sets the name of the collection.
28+
/// </summary>
29+
/// <value>
30+
/// The name of the collection.
31+
/// </value>
32+
public string? CollectionName { get; set; }
33+
1834
/// <summary>
1935
/// Gets or sets the name of the collection file.
2036
/// </summary>
Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System.Collections.Generic;
2-
using System.Reflection;
32
using Simplify.DI;
43
using Simplify.Web.Modules;
54
using Simplify.Web.Postman.Json;
65
using Simplify.Web.Postman.PartBuilders;
6+
using Simplify.Web.Postman.Settings;
77

88
namespace Simplify.Web.Postman
99
{
@@ -18,20 +18,44 @@ public static class SimplifyDIRegistratorExtensions
1818
/// <param name="registrator">The registrator.</param>
1919
/// <param name="settings">The settings.</param>
2020
/// <returns></returns>
21-
public static IDIRegistrator RegisterSimplifyWebPostman(this IDIRegistrator registrator, PostmanGenerationSettings? settings = null)
21+
public static IDIRegistrator RegisterSimplifyWebPostman(this IDIRegistrator registrator, IPostmanGenerationSettings? settings = null)
2222
{
23-
settings = DefaultPostmanGenerationSettingsFactory.CreateOrUpdateSettings(settings, Assembly.GetCallingAssembly().GetName().Name);
24-
25-
registrator.Register(r => new CollectionBuilder(new List<ICollectionPartBuilder>
26-
{
27-
new CollectionItemsBuilder()
28-
}))
29-
.Register<ICollectionExporter>(r => new FileCollectionExporter(r.Resolve<CollectionModelSerializer>(), r.Resolve<IEnvironment>(),
30-
settings))
31-
.Register<CollectionModelSerializer>()
23+
registrator.Register(r => settings ??= new PostmanGenerationSettings(), LifetimeType.Singleton);
24+
25+
registrator.RegisterPartBuilders()
26+
.RegisterCollectionBuilder()
27+
.RegisterCollectionExporter();
28+
29+
registrator.Register<CollectionModelSerializer>()
3230
.Register<PostmanGenerator>();
3331

3432
return registrator;
3533
}
34+
35+
private static IDIRegistrator RegisterPartBuilders(this IDIRegistrator registrator)
36+
{
37+
registrator.Register<CollectionHeaderBuilder>(LifetimeType.Singleton)
38+
.Register<CollectionItemsBuilder>(LifetimeType.Singleton);
39+
40+
return registrator;
41+
}
42+
43+
private static IDIRegistrator RegisterCollectionBuilder(this IDIRegistrator registrator)
44+
{
45+
return registrator.Register(r => new CollectionBuilder(new List<ICollectionPartBuilder>
46+
{
47+
r.Resolve<CollectionHeaderBuilder>(),
48+
r.Resolve<CollectionItemsBuilder>()
49+
}));
50+
}
51+
52+
private static IDIRegistrator RegisterCollectionExporter(this IDIRegistrator registrator)
53+
{
54+
return registrator.Register<ICollectionExporter>(r =>
55+
new FileCollectionExporter(r.Resolve<CollectionModelSerializer>(),
56+
r.Resolve<IEnvironment>(),
57+
r.Resolve<IPostmanGenerationSettings>()),
58+
LifetimeType.Singleton);
59+
}
3660
}
3761
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Simplify.DI;
2+
using Simplify.Web.Bootstrapper;
23
using Simplify.Web.Postman;
34

45
namespace TesterApp.Setup
@@ -7,7 +8,8 @@ public static class IocRegistrations
78
{
89
public static void Register()
910
{
10-
DIContainer.Current.RegisterSimplifyWebPostman();
11+
DIContainer.Current.RegisterSimplifyWeb()
12+
.RegisterSimplifyWebPostman();
1113
}
1214
}
1315
}

src/TesterApp/Startup.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
1616
if (env.IsDevelopment())
1717
app.UseDeveloperExceptionPage();
1818

19-
app.UseSimplifyWeb();
19+
app.UseSimplifyWebWithoutRegistrations();
2020

2121
DIContainer.Current.Verify();
2222

@@ -27,6 +27,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
2727
public void ConfigureServices(IServiceCollection services)
2828
{
2929
IocRegistrations.Register();
30+
31+
DIContainer.Current.Verify();
3032
}
3133
}
3234
}

0 commit comments

Comments
 (0)