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 type: Microsoft.Extensions.Hosting.IHostApplicationLifetime #209

Closed
ArnaudB88 opened this issue Aug 5, 2024 · 1 comment

Comments

@ArnaudB88
Copy link

See the original ticket in the dotnet runtime repository:
dotnet/runtime#104372

How I use the LightInject container in our dotnet8 asp.net core api project

var builder = WebApplication.CreateBuilder(args);
builder.Host
    .UseLightInject()
    .ConfigureContainer<ServiceContainer>(container =>
    {
        ConfigureContainer(container);
        ConfigureServicesWithContainer(container, builder.Services);//Add services to the container.
    });
var app = builder.Build(); //Results in the exception
...

void ConfigureContainer(IServiceContainer container)
{
    //Bootstrap container
    //https://www.lightinject.net/#assembly-scanning
     var dllFilePaths = Directory.GetFiles(AppContext.BaseDirectory, "MyNamespace.*.dll");
     foreach (var dllFilePath in dllFilePaths)
      {
           var assembly = Assembly.LoadFrom(dllFilePath);
           container.RegisterAssembly(assembly);
      }

    //Add/override registrations
    container.RegisterSingleton<AppSettings>(factory => AppSettingsFactory.Create());
}

Should this be:

  • fixed in the LightInject repo
  • dotnet runtime/SDK
  • in my own code while calling LightInject methods

Thanks

@ArnaudB88
Copy link
Author

Seems like the bug is resolved:
dotnet/roslyn#74676

(will be released under milestone 17.12)

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

1 participant