Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve IHubContext<THub, T> #114

Closed
adambajguz opened this issue Mar 6, 2022 · 4 comments
Closed

Unable to resolve IHubContext<THub, T> #114

adambajguz opened this issue Mar 6, 2022 · 4 comments

Comments

@adambajguz
Copy link

Hi, I have a problem with integration of Stashbox into an offical SignalR Server Example. Strangely a version that uses Microsoft.Extenstions.DependencyInjections works, but as soon as I add Stashbox by adding

	<ItemGroup>
		<PackageReference Include="Stashbox" Version="5.1.0" />
		<PackageReference Include="Stashbox.Extensions.Hosting" Version="4.0.1" />
	</ItemGroup>

to Server.csproj and

                .UseStashbox(container => // Optional configuration options.
                {
                    // This one enables the lifetime validation for production environments too.
                    container.Configure(config => config.WithLifetimeValidation());
                })
                .ConfigureContainer<IStashboxContainer>((context, container) =>
                {
                    // Execute a dependency tree validation.
                    if (context.HostingEnvironment.IsDevelopment())
                        container.Validate();
                })

to Program.cs, the example throws

Container validation failed. See the inner exceptions for details. (Unable to resolve type Server.Worker.
Constructor Void .ctor(Microsoft.Extensions.Logging.ILogger`1[Server.Worker], Microsoft.AspNetCore.SignalR.IHubContext`2[Server.ClockHub,HubServiceInterfaces.IClock]) found with unresolvable parameter: (Microsoft.AspNetCore.SignalR.IHubContext`2[[Server.ClockHub, Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[HubServiceInterfaces.IClock, HubServiceInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]])clockHub.
)

After Worker ctor modification

        public Worker(ILogger<Worker> logger, IServiceProvider serviceProvider)
        {
            _logger = logger;
            _clockHub = serviceProvider.GetService<IHubContext<ClockHub, IClock>>();
        }

I've found that serviceProvider.GetService<IHubContext<ClockHub, IClock>>() returns null.

Since IHubContext<THub, T> is an open generic registration, probably open generic type resolver does not function properly.

@z4kn4fein
Copy link
Owner

Thank you for reporting the issue, I'm going to check what's causing it!

z4kn4fein added a commit that referenced this issue Mar 6, 2022
z4kn4fein added a commit that referenced this issue Mar 7, 2022
commit 5bd4b32
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Mar 7 00:29:26 2022 +0100

    Update stashbox.csproj

commit 73712d6
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Mar 7 00:00:47 2022 +0100

    Update changelog

commit daf5515
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Mar 6 23:18:31 2022 +0100

    Update CHANGELOG.md

commit 5c28d00
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Mar 6 22:34:11 2022 +0100

    Update 114_Unable_to_resolve_IHubContext.cs

commit 4c754b9
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Mar 6 22:33:25 2022 +0100

    Fix for #114

commit 31da8fb
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 13:29:36 2022 +0100

    Update docs

commit a705b77
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 03:34:52 2022 +0100

    Update docs

commit 9a3d4c6
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 03:24:36 2022 +0100

    Update RequestContext.cs

commit 84dcaa7
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 03:19:25 2022 +0100

    Update docs

commit efce1da
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 03:14:59 2022 +0100

    Update changelog & docs

commit 29a3c6b
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 02:43:09 2022 +0100

    Pack readme

commit 1909815
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Thu Mar 3 01:11:52 2022 +0100

    Remove automatic pre-release package deployment to NuGet

commit 1acdd37
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Wed Mar 2 23:50:13 2022 +0100

    Update changelog, add ResolveFactoryOrDefault()

commit 1015495
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Wed Mar 2 17:44:14 2022 +0100

    Ability to exclude instance from dispose tracking in factory delegates

commit 74a99c2
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Tue Mar 1 21:21:09 2022 +0100

    Refactor

commit f0b5559
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Tue Mar 1 20:31:56 2022 +0100

    Refactor

commit fd96834
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Tue Mar 1 02:48:21 2022 +0100

    Enable null-safety

commit adbc669
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Feb 28 18:50:18 2022 +0100

    ServiceRegistration refactor

commit eccbe95
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Feb 28 03:46:12 2022 +0100

    Eliminate MemberwiseClone() usages

commit 44da27d
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Feb 28 01:37:11 2022 +0100

    More tests

commit 799557d
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Mon Feb 28 01:19:16 2022 +0100

    Small refactor

commit b3b6962
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Feb 27 18:36:13 2022 +0100

    Include dev branch in workflows

commit 3159cb5
Author: Peter Csajtai <peter.csajtai@outlook.com>
Date:   Sun Feb 27 18:34:11 2022 +0100

    ValueTuple support & ResolveOrDefault()
@z4kn4fein
Copy link
Owner

Hi @adambajguz, I released the fix in Stashbox v5.2.0 / Stashbox.Extensions.Hosting v4.1.0

@adambajguz
Copy link
Author

Hi @z4kn4fein, thanks I'll test this later today :)

@adambajguz
Copy link
Author

Hi @z4kn4fein, it works! Thanks for super fast fix 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants