Altinn / altinn-studio

Next generation open source Altinn platform and applications.
https://docs.altinn.studio
BSD 3-Clause "New" or "Revised" License
111 stars 70 forks source link

Unable to resolve service for type 'Altinn.App.PlatformServices.Interface.IEvents' #4993

Closed torbjokv closed 3 years ago

torbjokv commented 3 years ago

Describe the bug

Using latest version from master breaks the InstancesController instantiation when developing a form locally

To Reproduce

Steps to reproduce the behavior:

  1. Link dependencies directly in App\App.csproj

    <ItemGroup>
    <!--    <PackageReference Include="Altinn.App.Api" Version="1.1.6-alpha" />-->
    <!--    <PackageReference Include="Altinn.App.Common" Version="1.1.6-alpha" />-->
    <!--    <PackageReference Include="Altinn.App.PlatformServices" Version="1.1.6-alpha" />-->
    <ProjectReference Include="..\..\altinn-studio\src\Altinn.Apps\AppTemplates\AspNet\Altinn.App.Common\Altinn.App.Common.csproj" />
    <ProjectReference Include="..\..\altinn-studio\src\Altinn.Apps\AppTemplates\AspNet\Altinn.App.Api\Altinn.App.Api.csproj"/>
    <ProjectReference Include="..\..\altinn-studio\src\Altinn.Apps\AppTemplates\AspNet\Altinn.App.PlatformServices\Altinn.App.PlatformServices.csproj" />
    
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.8" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
    </ItemGroup>
  2. Make sure appsettings.json have all needed values. I had to update/add these:
    "GeneralSettings": {
    "HostName": "altinn3local.no",
    "SBLCookieName": ".ASPXAUTH",
    "BaseUrl": "http://altinn3local.no",
    "PlatformEndpoint": "http://localhost:5040/",
    "ClaimsIdentity": "UserLogin",
    "JwtCookieValidityTime": "30",
    "AltinnPartyCookieName": "AltinnPartyId"
    },
    "CertificateSettings": {
    "CertificatePwd": "qwer1234",
    "CertificatePath": "[PATH_TO_STUDIO_WINSTYLEPATH]\\src\\development\\LocalTest\\jwtselfsignedcert.pfx"
    },
    "AuthnGeneralSettings": {
    "HostName": "at22.altinn.cloud",
    "SBLCookieName": ".ASPXAUTH",
    "BaseUrl": "http://localhost",
    "BridgeApiEndpoint": "https://at22.altinn.cloud/sblbridge/authentication/api/",
    "SBLRedirectEndpoint": "https://at22.altinn.cloud/ui/authentication/",
    "PlatformEndpoint": "http://localhost:5101/",
    "ClaimsIdentity": "UserLogin",
    "JwtCookieValidityTime": "30",
    "AltinnPartyCookieName": "AltinnPartyId",
    "MaskinportenWellKnownConfigEndpoint": "https://ver2.maskinporten.no/.well-known/oauth-authorization-server",
    "OrganisationRepositoryLocation": "https://altinncdn.no/orgs/altinn-orgs.json"
    },
    "AllowedHosts": "*",
    "LocalPlatformSettings": {
    "LocalTestingStorageBasePath": "[PATH_TO_STUDIO_NIXSTYLEPATH]",
    "AppRepsitoryBasePath": "[PATH_TO_REPOS_NIXSTYLEPATH]",
    "LocalTestingStaticTestDataPath": [PATH_TO_REPOS_NIXSTYLEPATH]/src/development/TestData/"
    },
  3. Start studio and form application
  4. Try to instantiate new form instance with http://altinn3local.no/
  5. Request fails with exception
    info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'Altinn.App.Api.Controllers.InstancesController.Post (Altinn.App.Api)'
    fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
    System.InvalidOperationException: Unable to resolve service for type 'Altinn.App.PlatformServices.Interface.IEvents' while attempting to activate 'Altinn.App.Api.Controllers.InstancesController'.
    at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
    at lambda_method(Closure , IServiceProvider , Object[] )
    at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
    at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|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 where exception was thrown ---
    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_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 where exception was thrown ---
    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
    at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|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.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Expected behavior

Instantiating new form instance should create new instance without exceptions

Additional info

Could be caused by this PR https://github.com/Altinn/altinn-studio/pull/4923

jeevananthank commented 3 years ago

@torbjokv can you try to update the app with the breaking changes mentioned here and let us know if the app instantiation is failing again.

SandGrainOne commented 3 years ago

We currently need to update Startup.cs i an existing app when new services are added. Sorry about that. This is something we hope to avoid in the future. #4895

The project change you've made means you are going from Altinn.App.* package version 1.1.6 to 1.1.11. Please check the breaking-changes Jeeva linked above. There might be multiple things to change in the App.

torbjokv commented 3 years ago

@torbjokv can you try to update the app with the breaking changes mentioned here and let us know if the app instantiation is failing again.

oh, you've totally right! My bad for not checking the breaking changes page. Its bookmarked now :-) I will close this issue!

Thanks for your help @jeevananthank and @SandGrainOne