✅ Contracts.dll for Domain not being activated
Hi, I'm trying out to build a Domain project where I have a Contracts project, that will have the interfaces (and logics) used in the Webclient.
I'm getting this error:
System.InvalidOperationException: Unable to resolve service for type 'Workcruit.Domain.Contracts.Interfaces.ITestInterface' while attempting to activate 'BackendForFrontend.Controllers.AuthController'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method8(Closure, IServiceProvider, Object[])
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>cDisplayClass6_0.<CreateControllerFactory>gCreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>gAwaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>gLogged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>gLogged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
My code in the Domain:
Code in the WebClient:
Getting the error written at the top of this thread.
24 Replies
System.InvalidOperationException: Unable to resolve service for type 'Workcruit.Domain.Contracts.Interfaces.ITestInterface' while attempting to activate 'BackendForFrontend.Controllers.AuthControllerYou have not registered
ITestInterface
with your IoC containerHmm, how do I register it in the IoC container? I'm pretty new to Domain 😛
I know how to work with Domains, but not creating them
no idea what
Domain
is
but somewhere you're using Microsoft.Extensions.DependencyInjection
But I'm registering the ITestService in my Program.cs
This is how it looks in the WebClient:
This is the Program.cs in the other project:
Trying to expose the Contracts project, and I'm able to see the interfaces in my other project, but they aren't getting activated.
okay, so
.Domain
is the project you're running that is throwing?It's throwing inside the
.WebClient
project, that's a seperate project, even though it's activated in the .Domain
project 😛uhm
well, I don't see any
.WebClient
project, for oneIt's not in the same solution, it's two completely different projects
then why are we looking at code in this solution?
specifically, why are we not looking at the bootstrapping code for the project where the issue is actually happening?
why are we looking at code that doesn't RUN in the project where the issue is actually happening?
This is how it's setup inside the project where it's crashing
does the
.WebClient
project load .Domain
and call Program.CreateHostBuilder
?
that's not a setup for anything
and you already posted that
that snippet does not contain an IoC registration for ITestInterface
But I don't have access to the implementation, only the Interface, so how would I activate it in the
.WebClient
Projhect?huh?
we're talking about registering it
the IoC container activates it
how would you not "have access" to it?
where is your IoC setup code in
.WebClient
?there is no registration for
ITestInterface
Tried doing that. I'm getting this error:
System.ArgumentException: 'Cannot instantiate implementation type 'Workcruit.Domain.Contracts.Interfaces.ITestInterface' for service type 'Workcruit.Domain.Contracts.Interfaces.ITestInterface'.'
right, you have register a concrete type
what implementation of
ITestInterface
do you intend to use in .WebClient
if you can't do
how do you expect the IoC container to?I'm just trying to setup the
.Domain
project.
It's mostly to seperate logics. So Core/Business logics etc. will be in the .Domain
, and the WebApp/WebClient will be in .WebClient
.
But It's supposed to be SQL queries etc. in the .Domain
that sounds wonderful and irrelevant to me
what implementation ofITestInterface
do you intend to use in.WebClient
The ITestInterface will be removed once I get this working. Currently the ITestInterface is just to get the two projects working together. ITestInterface has a Test() method, that just returns a string.
So, there is no purpose of ITestInterface other than getting the two projects to actually work together, so I actually can implement the logics I want..
once I get this workingget what working? What is not working other than your attempts to use
ITestInterface
? How is ITestInterface
supposed to "get the two projects working together"? What does "get the two projects working together" even mean?Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.