Skip to content

Commit 2d67553

Browse files
authored
Fix/isolation (#633)
* fix:isolation * fix:oss isolation and event dispatcher order * fix:code smell
1 parent 3de695b commit 2d67553

File tree

13 files changed

+129
-45
lines changed

13 files changed

+129
-45
lines changed

src/BuildingBlocks/Isolation/Masa.BuildingBlocks.Isolation/Internal/ComponentConfigUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
[assembly: InternalsVisibleTo("Masa.Contrib.Caching.Distributed.StackExchangeRedis")]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Isolation;
5+
6+
public static class DccConsts
7+
{
8+
public const string PUBLIC_ID = "public-$Config";
9+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
namespace Masa.BuildingBlocks.Storage.ObjectStorage;
@@ -7,12 +7,12 @@ public class DefaultBucketNameFactory : MasaFactoryBase<IBucketNameProvider, Mas
77
{
88
protected override string DefaultServiceNotFoundMessage => "No default ObjectStorageBucketName found";
99
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] ObjectStorageBucketName, it was not found";
10-
protected override MasaFactoryOptions<MasaRelationOptions<IBucketNameProvider>> FactoryOptions => _options.CurrentValue;
10+
protected override MasaFactoryOptions<MasaRelationOptions<IBucketNameProvider>> FactoryOptions => _options.Value;
1111

12-
private readonly IOptionsMonitor<BucketNameFactoryOptions> _options;
12+
private readonly IOptions<BucketNameFactoryOptions> _options;
1313

1414
public DefaultBucketNameFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1515
{
16-
_options = serviceProvider.GetRequiredService<IOptionsMonitor<BucketNameFactoryOptions>>();
16+
_options = serviceProvider.GetRequiredService<IOptions<BucketNameFactoryOptions>>();
1717
}
1818
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
namespace Masa.BuildingBlocks.Storage.ObjectStorage;
@@ -8,12 +8,12 @@ public class DefaultObjectStorageClientFactory : MasaFactoryBase<IManualObjectSt
88
protected override string DefaultServiceNotFoundMessage => "No default ObjectStorage found";
99
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] ObjectStorage, it was not found";
1010

11-
protected override MasaFactoryOptions<MasaRelationOptions<IManualObjectStorageClient>> FactoryOptions => _options.CurrentValue;
11+
protected override MasaFactoryOptions<MasaRelationOptions<IManualObjectStorageClient>> FactoryOptions => _options.Value;
1212

13-
private readonly IOptionsMonitor<ObjectStorageFactoryOptions> _options;
13+
private readonly IOptions<ObjectStorageFactoryOptions> _options;
1414

1515
public DefaultObjectStorageClientFactory(IServiceProvider serviceProvider) : base(serviceProvider)
1616
{
17-
_options = serviceProvider.GetRequiredService<IOptionsMonitor<ObjectStorageFactoryOptions>>();
17+
_options = serviceProvider.GetRequiredService<IOptions<ObjectStorageFactoryOptions>>();
1818
}
1919
}

src/BuildingBlocks/Storage/Masa.BuildingBlocks.Storage.ObjectStorage/Extensions/ServiceCollectionExtensions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
// ReSharper disable once CheckNamespace
@@ -28,15 +28,15 @@ private static void AddObjectStorageCore(this IServiceCollection services, strin
2828
MasaArgumentException.ThrowIfNull(services);
2929
MasaArgumentException.ThrowIfNull(name);
3030

31-
services.TryAddSingleton<SingletonService<IManualObjectStorageClient>>(serviceProvider
31+
services.TryAddSingleton(serviceProvider
3232
=> new SingletonService<IManualObjectStorageClient>(serviceProvider.GetRequiredService<IObjectStorageClientFactory>()
3333
.Create()));
34-
services.TryAddScoped<ScopedService<IManualObjectStorageClient>>(serviceProvider
34+
services.TryAddScoped(serviceProvider
3535
=> new ScopedService<IManualObjectStorageClient>(serviceProvider.GetRequiredService<IObjectStorageClientFactory>().Create()));
3636

37-
services.TryAddSingleton<SingletonService<IBucketNameProvider>>(serviceProvider
37+
services.TryAddSingleton(serviceProvider
3838
=> new SingletonService<IBucketNameProvider>(serviceProvider.GetRequiredService<IBucketNameFactory>().Create()));
39-
services.TryAddScoped<ScopedService<IBucketNameProvider>>(serviceProvider
39+
services.TryAddScoped(serviceProvider
4040
=> new ScopedService<IBucketNameProvider>(serviceProvider.GetRequiredService<IBucketNameFactory>().Create()));
4141

4242
services.TryAddObjectStorageClient();
@@ -61,13 +61,10 @@ private static void TryAddObjectStorageClient(this IServiceCollection services)
6161

6262
private static void TryAddBucketNameProvider(this IServiceCollection services)
6363
{
64-
services.TryAddTransient<IBucketNameProvider>(serviceProvider =>
65-
{
66-
if (serviceProvider.EnableIsolation())
67-
return serviceProvider.GetRequiredService<ScopedService<IBucketNameProvider>>().Service;
64+
services.TryAddTransient(serviceProvider => serviceProvider.EnableIsolation() ?
65+
serviceProvider.GetRequiredService<ScopedService<IBucketNameProvider>>().Service :
66+
serviceProvider.GetRequiredService<SingletonService<IBucketNameProvider>>().Service);
6867

69-
return serviceProvider.GetRequiredService<SingletonService<IBucketNameProvider>>().Service;
70-
});
7168
services.TryAddTransient<IBucketNameFactory, DefaultBucketNameFactory>();
7269
}
7370

src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events/Internal/Dispatch/DispatchNetworkRoot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
// ReSharper disable once CheckNamespace
@@ -20,7 +20,7 @@ public DispatchNetworkRoot(List<IDispatchNetworkProvider> providers)
2020
private static Dictionary<Type, List<DispatchRelationOptions>> BuildDispatchNetworks(List<IDispatchNetworkProvider> providers)
2121
{
2222
return BuildDispatchNetworks(
23-
providers.SelectMany(provider => provider.HandlerNetwork).ToList(),
23+
providers.SelectMany(provider => provider.HandlerNetwork).OrderBy(provider => provider.Order).ToList(),
2424
providers.SelectMany(provider => provider.CancelHandlerNetwork).ToList());
2525
}
2626

src/Contrib/Dispatcher/Masa.Contrib.Dispatcher.Events/Internal/Dispatch/LocalEventBus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
// ReSharper disable once CheckNamespace

src/Contrib/Dispatcher/Tests/Masa.Contrib.Dispatcher.Events.Tests/EventHandlers/MarketingEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) MASA Stack All rights reserved.
1+
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
namespace Masa.Contrib.Dispatcher.Events.Tests.EventHandlers;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.Contrib.ReadWriteSplitting.Cqrs.Tests.Commands;
5+
6+
internal record OrderCommand(bool Cancel) : Command
7+
{
8+
public int Count { get; set; }
9+
}

src/Contrib/ReadWriteSplitting/Tests/Masa.Contrib.ReadWriteSplitting.Cqrs.Tests/CqrsTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ public void TestCommand(string name)
4141
}
4242
}
4343

44+
[DataTestMethod]
45+
[DataRow(false)]
46+
[DataRow(true)]
47+
public void TestOrderCommand(bool cancel)
48+
{
49+
var command = new OrderCommand(cancel);
50+
_eventBus.PublishAsync(command);
51+
if (cancel)
52+
{
53+
Assert.IsTrue(command.Count == 0);
54+
}
55+
else
56+
{
57+
Assert.IsTrue(command.Count == int.MaxValue);
58+
}
59+
}
60+
4461
[TestMethod]
4562
public void TestQuery()
4663
{

0 commit comments

Comments
 (0)