Skip to content

Is there a way to parameterize and pass an instance of Startup rather than just the type? #831

Closed
@humblelistener

Description

@humblelistener

The intention is to avoid creating a separate TestStartUp class rather - rather inject an instance of Configuration

Sample start up below,

public class Startup
{
  public IConfiguration Configuration {get; set;}

  public void Startup()
  {
    Configuration = new ConfigurationBuilder()
              .AddEnvironmentVariables()
              .Build();
   }

  public void ConfigureServices(IServiceCollection services)
  {
     //uses Configuration object to set up everything
  }
}

In the above implementation, if only

TestServer.CreateBuilder().UseStartup(instanceOfStartup)
is permitted

I can do this,

Startup instanceOfStartup= new Startup();
instanceOfStartup.Configuration = myOwnconfigurationWithKeysRequiredForTest;
//create a test server with 
TestServer.CreateBuilder().UseStartup(instanceOfStartup) 

Advantage: I dont have to maintain multiple startup class.

Does it make sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions