我们决定在应用程序中使用新的DynamoDbAppSettings类来利用DynamoDb。我们目前正在使用从AppSettings继承的自定义类(以下所示的类的一部分):
public class MyAppSettings : AppSettings
{
public ApplicationEnvironment Environment
{
get { return Get("Environment", ApplicationEnvironment.Development); }
}
public List<string> AdministratorEmails
{
get { return Get("AdminEmailAddresses", new List<string>()); }
}
public string CompanyReadConnectionString
{
get
{
string settingsName = "CompanyReadConnectionString_{0}".Fmt(Environment);
return Get(settingsName, string.Empty);
}
}
}我不太清楚的是如何转换到MultiAppSettings。例如,我们目前注册的AppSettings如下:
//Custom App settings
container.RegisterAutoWired<MyAppSettings>();
MyAppSettings appSettings = container.Resolve<MyAppSettings>();然后,我可以使用appSettings变量很容易地访问我的应用程序设置,在自定义类中检查所有的缺省值等等,再加上在我的应用程序中没有“魔法字符串”的好处。例如,我可以很容易地通过以下方法获得调试模式:
appSettings.DebugMode对于DynamoDb,我添加了类似于示例中所示的代码:
MultiAppSettings multiAppSettings = new MultiAppSettings(
new DynamoDbAppSettings(
new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()), true),
new MyAppSettings());但我不清楚现在该如何处理它。我如何或者如何才能拥有一个像上面所示的使用MultiAppSettings的自定义类?如果是的话,我如何注册它并访问我的应用程序设置?在声明MultiAppSetting变量时,使用我现有的自定义类作为回退是否合适?如果有更多关于如何使用DynamoDbAppSettings的建议,我将不胜感激。
发布于 2016-05-09 21:00:05
AWSApps AppHost展示了一个通过在AppHost构造函数中分配base.AppSettings来使用DynamoDbAppSettings的示例,例如:
public AppHost() : base("AWS Examples", typeof(AppHost).Assembly)
{
#if !DEBUG
//Deployed RELEASE build uses Config settings in DynamoDb
AppSettings = new MultiAppSettings(
new DynamoDbAppSettings(newPocoDynamo(AwsConfig.CreateAmazonDynamoDb()),
initSchema:true),
new AppSettings());
#endif
}现在,它将取代base.AppSettings提供程序,只需查看Web.config的<appSettings/>,然后在不存在特定条目时返回到Web.config appSettings。
例如,这在AppHost.Configure() to 为每个注册的AuthProvider填充API键中使用
return new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[]
{
new CredentialsAuthProvider(), //HTML User/Pass
new BasicAuthProvider(), //HTTP Basic Auth
new DigestAuthProvider(AppSettings), //HTTP Digest Auth
new TwitterAuthProvider(AppSettings), //Twitter
new FacebookAuthProvider(AppSettings), //Facebook
new YahooOpenIdOAuthProvider(AppSettings), //Yahoo OpenId
new OpenIdOAuthProvider(AppSettings), //Custom OpenId
new GoogleOAuth2Provider(AppSettings), //Google OAuth2
new LinkedInOAuth2Provider(AppSettings), //LinkedIn OAuth2
new GithubAuthProvider(AppSettings), //GitHub OAuth Provider
})
{
HtmlRedirect = "/awsauth/",
IncludeRegistrationService = true,
};IAppSettings是在Funq中自动注册的,因此您的服务可以像任何其他依赖项一样访问它,例如:
public class MyServices : Service
{
public IAppSettings AppSettings { get; set; }
}https://stackoverflow.com/questions/37121945
复制相似问题