Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

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

Closed
@Tratcher

Description

@Tratcher

From @humblelistener on August 14, 2015 5:8

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?

Copied from original issue: dotnet/aspnetcore#831

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions