我正在尝试使用 MongoDB 作为 ServiceStack 的身份验证模块的持久化后端,因此我在以下节点中添加了以下节点web.config
:
<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
?