servicestack,amazon-dynamodb,C#,.net,servicestack,Amazon Dynamodb" /> servicestack,amazon-dynamodb,C#,.net,servicestack,Amazon Dynamodb" />

C# 如何用ServiceStack中的MultiAppSetting类替换自定义AppSetting类?

C# 如何用ServiceStack中的MultiAppSetting类替换自定义AppSetting类?,c#,.net,servicestack,amazon-dynamodb,C#,.net,servicestack,Amazon Dynamodb,我们决定在应用程序中使用新的DynamoDbAppSettings类来利用DynamoDb。我们当前使用的自定义类继承自AppSettings(类的一部分,如下所示): 对于DynamoDb,我添加了如下示例所示的代码: MultiAppSettings multiAppSettings = new MultiAppSettings( new DynamoDbAppSettings( new PocoDynamo(AwsConfig.CreateAmazonDynamoD

我们决定在应用程序中使用新的DynamoDbAppSettings类来利用DynamoDb。我们当前使用的自定义类继承自AppSettings(类的一部分,如下所示):

对于DynamoDb,我添加了如下示例所示的代码:

MultiAppSettings multiAppSettings = new MultiAppSettings(
      new DynamoDbAppSettings(
      new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()), true),
            new MyAppSettings());
但目前我不清楚如何使用它。我如何或者可以拥有一个自定义类,如上图所示,它可以与MultiAppSettings一起工作?如果是,我如何注册并访问我的应用程序设置?在声明MultiAppSetting变量时,使用现有自定义类作为回退是否合适?如果您有更多关于使用DynamoDbAppSettings的建议,我们将不胜感激。

显示了通过在AppHost构造函数中分配
base.AppSettings
MultiAppSettings
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
}
它现在将取代仅查看Web.config的
base.AppSettings
提供程序:

IAppSettings
自动在Funq中注册,以便您的服务可以像访问任何其他依赖项一样访问它,例如:

public class MyServices : Service
{
    public IAppSettings AppSettings { get; set; }
}

谢谢你的回复。在上面的示例中,我将基于多AppSetting为自定义类设置AppSettings,即,
AppSettings=new MyAppSettings(new DynamoDbAppSettings(new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()),true))。虽然我可以引用AppSettings,但代码不知道它是我的自定义类。使用
(MyAppSettings)AppSettings.MyProperty
无效。我可以使用
var-appSettings=appSettings作为MyAppSettings
,但感觉很尴尬。有什么建议吗?@Tortillabevent这只是普通的C#,
IAppSettings
(或任何相关的提供者)背后的想法是,你的类不应该知道你的具体AppSettings提供者,因此你可以在以后根据需要配置AppSetting源,它仍然有效,因此,我强烈反对回溯到您的具体类型,但如果您想继续这样做,您可以将属性访问隐藏在类型化扩展方法后面。在我的例子中,我有一个强类型的AppSettings类,并试图不中断它或我的代码。我希望使这个现有类基于
MultiAppSettings
,而不仅仅是
appattings
。如果我在声明中将AppSettings更改为MultiAppSettings,那么我将不得不使用魔术字符串在任何地方引用我的AppSettings,而现在我可以只使用
AppSettings.Property
,并且我知道编译过程中的任何错误。我从ServiceStack 4烹饪书中得到了包装器的想法,但是如果我使用MultiAppSettings方法,这个方法现在就不可用了吗?你可以在类型化扩展方法后面包装魔术字符串,或者使用带有字符串常量的静态类。暴露一个具体的类显然不利于可替换性。
MultiAppSettings multiAppSettings = new MultiAppSettings(
      new DynamoDbAppSettings(
      new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()), true),
            new MyAppSettings());
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
}
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,
};
public class MyServices : Service
{
    public IAppSettings AppSettings { get; set; }
}