1
我試圖使用MongoDB的作爲持久性後端爲ServiceStack的認證模塊,所以我增加了以下節點web.config
:如何配置的MongoDB在servicestack
<connectionStrings>
<add name="myDb" connectionString="mongodb://localhost/mydb?safe=true" />
</connectionStrings>
在這裏,下面是我的Configure
方法:
public class MyAppHost : AppHostBase
{
public MyAppHost() : base("My Web Services", typeof(MyService).Assembly)
{
}
public override void Configure(Container container)
{
Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
new BasicAuthProvider()
}));
Plugins.Add(new RegistrationFeature());
var connectionString = ... // how do I retrieve "mongodb://localhost"?
var dbName = ... // how do I retrieve "mydb"?
var mongoClient = new MongoClient(connectionString);
var server = mongoClient.GetServer();
var db = server.GetDatabase(dbName);
container.Register<ICacheClient>(new MemoryCacheClient());
container.Register<IUserAuthRepository>(new MongoDBAuthRepository(db, true));
}
}
如何檢索web.config
連接字符串和數據庫的名字嗎?