Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.12.0
- Add suffix to member name for interfaces with the same name from different namespaces to resolve conflict (https://github.com/pakrym/jab/pull/187).

## 0.11.0
- Factory-created services are now correctly disposed (https://github.com/pakrym/jab/pull/179).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Jab provides a [C# Source Generator](https://devblogs.microsoft.com/dotnet/intro
Add Jab package reference:
```xml
<ItemGroup>
<PackageReference Include="Jab" Version="0.11.0" PrivateAssets="all" />
<PackageReference Include="Jab" Version="0.12.0" PrivateAssets="all" />
</ItemGroup>
```

Expand Down Expand Up @@ -283,7 +283,7 @@ A minimal example ends up looking like this:
}
],
"dependencies": {
"com.pakrym.jab": "0.11.0",
"com.pakrym.jab": "0.12.0",
...
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jab.Attributes/Jab.Attributes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>preview</LangVersion>
<RootNamespace>Jab</RootNamespace>
<DefineConstants>$(DefineConstants);JAB_ATTRIBUTES_PACKAGE;GENERIC_ATTRIBUTES</DefineConstants>
<Version>0.11.0</Version>
<Version>0.12.0</Version>
<Version Condition="'$(ReleaseVersion)' != ''">$(ReleaseVersion)</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
35 changes: 33 additions & 2 deletions src/Jab.FunctionalTests.Common/ContainerTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#nullable enable
using Jab;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;

using Jab;

namespace JabTests
{
public partial class ContainerTests
Expand Down Expand Up @@ -1448,6 +1449,36 @@ public void SupportsNoneTransientValueType()
internal partial class SupportsNoneTransientValueTypeContainer
{
}


[Fact]
public void GeneratesDistinctMembersForSameLocalNameAcrossNamespaces()
{
var c = new NameCollisionContainer();

var foo1 = c.GetService<IService>();
var foo2 = c.GetService<NestedNS.IService>();

Assert.NotNull(foo1);
Assert.NotNull(foo2);
Assert.NotSame(foo1, foo2);

// Verify distinct private cache fields were generated (e.g. _IFoo_0, _IFoo_1)
var fields = typeof(NameCollisionContainer)
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
.Where(f => f.Name.StartsWith("_IService", StringComparison.Ordinal))
.Select(f => f.Name)
.Distinct()
.ToArray();

Assert.Equal(2, fields.Length);
Assert.NotEqual(fields[0], fields[1]);
}

[ServiceProvider]
[Singleton(typeof(IService), typeof(ServiceImplementation))]
[Singleton(typeof(NestedNS.IService), typeof(NestedNS.ServiceImplementation))]
internal partial class NameCollisionContainer { }
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Jab.FunctionalTests.Common/Mocks/NestedNS/IService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Jab;

namespace JabTests.NestedNS
{
internal interface IService
{
}
internal interface IService<T>
{
T InnerService { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Jab;

namespace JabTests.NestedNS
{
internal class ServiceImplementation : IService
{
}

internal class ServiceImplementation<T> : IService<T>
{
public ServiceImplementation(T innerService)
{
InnerService = innerService;
}

public T InnerService { get; }
}
}
2 changes: 1 addition & 1 deletion src/Jab.Unity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.pakrym.jab",
"version": "0.11.0",
"version": "0.12.0",
"description": "C# Source Generator based dependency injection container implementation.",
"licensesUrl": "https://github.com/pakrym/jab/blob/main/LICENSE",
"repository": {
Expand Down
Loading