Skip to content

Commit

Permalink
added the failing test for #555
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Feb 16, 2023
1 parent 055c880 commit 2a1c23c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/DryIoc.Microsoft.DependencyInjection/DryIocAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public DryIocServiceProviderFactory(
/// unless the `registrySharing` is set to the `RegistrySharing.Share` or to `RegistrySharing.CloneButKeepCache`.
/// `registerDescriptor` is the custom service descriptor handler.
/// </summary>
public DryIocServiceProviderFactory(IContainer container, RegistrySharing registrySharing,
public DryIocServiceProviderFactory(
IContainer container,
RegistrySharing registrySharing,
Func<IRegistrator, ServiceDescriptor, bool> registerDescriptor = null)
{
_container = container;
Expand All @@ -94,7 +96,7 @@ public IContainer CreateBuilder(IServiceCollection services) =>
(_container ?? new Container(Rules.MicrosoftDependencyInjectionRules))
.WithDependencyInjectionAdapter(services, _registerDescriptor, _registrySharing);

/// <inheritdoc />
/// <summary>The <paramref name="container"/> is the container returned by the <see cref="CreateBuilder(IServiceCollection)"/> method.</summary>
public IServiceProvider CreateServiceProvider(IContainer container) =>
container.BuildServiceProvider();
}
Expand Down
1 change: 1 addition & 0 deletions test/DryIoc.IssuesTests/DryIoc.IssuesTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\DryIoc.Microsoft.DependencyInjection\DryIoc.Microsoft.DependencyInjection.csproj" />
<ProjectReference Include="..\..\src\DryIoc.MefAttributedModel\DryIoc.MefAttributedModel.csproj" />
<ProjectReference Include="..\..\test_sut\DryIoc.MefAttributedModel.UnitTests.CUT\DryIoc.MefAttributedModel.UnitTests.CUT.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using NUnit.Framework;
using Microsoft.Extensions.DependencyInjection;
using DryIoc.Microsoft.DependencyInjection;

namespace DryIoc.IssuesTests
{
[TestFixture]
public class GHIssue555_ConcreteTypeDynamicRegistrations_is_not_working_with_MicrosoftDependencyInjectionRules : ITest
{
public int Run()
{
Test1();
return 1;
}

[Test]
public void Test1()
{
var rules = Rules
.MicrosoftDependencyInjectionRules
.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient);

var container = new Container(rules);

// container with MS.DI rules should not be cloned
var msDi = new DryIocServiceProviderFactory(container);
var msDiContainer = msDi.CreateBuilder(new ServiceCollection());
// Assert.AreSame(container, msDiContainer); // todo: @fixme
}

public interface IServiceA
{
string Text { get; }
}

public class ServiceA : IServiceA
{
public string Text { get; set; }
}
}
}

0 comments on commit 2a1c23c

Please sign in to comment.