Skip to content

Overriding bindings from test project #56

@psyren89

Description

@psyren89

In a regular ASP.NET project, for example, you can set up your DI via Startup.cs:

services.AddSingleton<IServiceA, ServiceA>()
  .AddSingleton<IServiceB, ServiceB>();

and in the test project, you can do this to override the configured DI for the main project (see here):

builder.ConfigureTestServices(services => services.AddSingleton<IServiceA, MockServiceA>());

Is there a way to do something similar with this library? I have tried the following:
Main project (has no knowledge of test project):

// Composition.cs
public partial class Composition;

// Startup.cs
DI.Setup("Namespace.Composition").Bind<IServiceA>().As(Lifetime.Singleton).To<ServiceA>().Root<IServiceA>();

Test project (references main project):

// BaseTest.cs
DI.Setup("Namespace.Composition")
  .Bind<IServiceA>().As(Lifetime.Singleton).To(_ => Mock.Of<IServiceA>).Root<IServiceA>();

Inspecting the Composition instance and stepping through the code during debugging shows that the test setup isn't overriding the original as I'd like. Is there an approach I should use?

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions