将idocumentStore设置为ravendb .net中的静态变量
我有一个继承 RavenTestDriver 的类。 我第一次需要初始化 IDocumentStore。因为出于某种原因我只需要这个类的一个对象。 所以这是我的代码:
public sealed class mystatic : RavenTestDriver
{
public static IDocumentStore store;
// here something like this store= GetDocumentStore()
public static IHostBuilder host = easy.api.Program.CreateHostBuilder(new string[0])
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder.UseTestServer();
}).ConfigureAppConfiguration(config =>
{
//config.AddJsonFile("appsettings.json", optional: true);
})
.ConfigureServices(services =>
{
services.AddScoped<ICurrentUserService, InitRequest>();
services.AddScoped<ICacheStorage>(provider =>
{
return new Mock<ICacheStorage>().Object;
});
services.AddTransient<IAsyncDocumentSession>((c) =>
{
return store.OpenAsyncSession();
});
});
public static IHost cli = host.Start();
}
我的问题是如何初始化商店变量? 或者如何在静态类中使用 GetDocumentStore() 初始化存储?
I have a class that inherits RavenTestDriver.
I need to initialize the IDocumentStore just for the first time . Because for some reason I need just one object of this class .
So here is my code :
public sealed class mystatic : RavenTestDriver
{
public static IDocumentStore store;
// here something like this store= GetDocumentStore()
public static IHostBuilder host = easy.api.Program.CreateHostBuilder(new string[0])
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder.UseTestServer();
}).ConfigureAppConfiguration(config =>
{
//config.AddJsonFile("appsettings.json", optional: true);
})
.ConfigureServices(services =>
{
services.AddScoped<ICurrentUserService, InitRequest>();
services.AddScoped<ICacheStorage>(provider =>
{
return new Mock<ICacheStorage>().Object;
});
services.AddTransient<IAsyncDocumentSession>((c) =>
{
return store.OpenAsyncSession();
});
});
public static IHost cli = host.Start();
}
My question is how can I initialize the store variable ??
Or How can I initialize the store with GetDocumentStore() in static class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)