Skip to content

Commit

Permalink
Merge pull request #38 from WeihanLi/patch-1
Browse files Browse the repository at this point in the history
Use TryAdd to register services
  • Loading branch information
catcherwong authored Mar 29, 2022
2 parents c12593c + a88fcd3 commit 57df6f6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Dtmcli/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DtmCommon;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;

namespace Dtmcli
Expand Down Expand Up @@ -56,14 +57,14 @@ private static void AddHttpClient(IServiceCollection services, DtmOptions option
private static void AddDtmCore(IServiceCollection services)
{
// trans releate
services.AddSingleton<IDtmTransFactory, DtmTransFactory>();
services.AddSingleton<IDtmClient, DtmClient>();
services.AddSingleton<TccGlobalTransaction>();
services.TryAddSingleton<IDtmTransFactory, DtmTransFactory>();
services.TryAddSingleton<IDtmClient, DtmClient>();
services.TryAddSingleton<TccGlobalTransaction>();

DtmCommon.ServiceCollectionExtensions.AddDtmCommon(services);

// barrier factory
services.AddSingleton<IBranchBarrierFactory, DefaultBranchBarrierFactory>();
services.TryAddSingleton<IBranchBarrierFactory, DefaultBranchBarrierFactory>();
}
}
}
}

0 comments on commit 57df6f6

Please sign in to comment.