Roman
Roman

Reputation: 643

ServiceStackHost.Instance has already been set (BasicAppHost)

I am using xunit to run test. One by one it works just fine but once I run them in parallel servicestack throws exception.

 System.IO.InvalidDataException : ServiceStackHost.Instance has already been set (BasicAppHost)
   at ServiceStack.ServiceStackHost.Init() in C:\BuildAgent\work\799c742886e82e6\src\ServiceStack\ServiceStackHost.cs:line 175    

appHost = new BasicAppHost(typeof(AppHost).GetAssembly())
                {
                    ConfigureContainer = container =>
                    {
                        container.Register<IDbConnectionFactory>(
                            new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
                    }
                }
                .Init();

Upvotes: 1

Views: 505

Answers (2)

ランス
ランス

Reputation: 550

You can use ICollectionFixture.

Initialize the appHost in a class like BaseFixture.

See sample here: https://xunit.net/docs/shared-context

Upvotes: 0

mythz
mythz

Reputation: 143369

You can only have a single AppHost initialized per AppDomain at any one time. If you are going to run tests in parallel which initialize a new AppHost they must be run in separate AppDomains.

Upvotes: 2

Related Questions