本文整理汇总了C#中AppSettings.Get方法的典型用法代码示例。如果您正苦于以下问题:C# AppSettings.Get方法的具体用法?C# AppSettings.Get怎么用?C# AppSettings.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppSettings
的用法示例。
在下文中一共展示了AppSettings.Get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
var appSettings = new AppSettings();
var connString = appSettings.Get("SQLSERVER_CONNECTION_STRING",
ConfigUtils.GetConnectionString("UserAuth"));
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(connString, SqlServerDialect.Provider));
//Using an in-memory cache
container.Register<ICacheClient>(new MemoryCacheClient());
ConfigureAuth(container);
var dbFactory = container.Resolve<IDbConnectionFactory>();
dbFactory.Run(d => d.CreateTableIfNotExists<UserAuth>());
dbFactory.Run(db => db.CreateTableIfNotExists<Message>());
dbFactory.Run(d => d.CreateTableIfNotExists<Device>());
SetConfig(new EndpointHostConfig
{
DefaultContentType = ContentType.Json,
EnableFeatures = Feature.All.Remove(Feature.Html).Remove(Feature.Xml),
AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Json }
});
//Or if Haz Redis
//container.Register<ICacheClient>(new PooledRedisClientManager());
}
示例2: StandardObjectInitialization
public void StandardObjectInitialization()
{
AppSettings settings = new AppSettings();
settings.Initialize( s => s == "Test" ? (object)3712 : null );
Assert.That( settings.Get( "Test" ), Is.EqualTo( 3712 ) );
Assert.That( settings.Get<int>( "Test", -5 ), Is.EqualTo( 3712 ) );
Assert.That( settings.Get<int>( "None", -5 ), Is.EqualTo( -5 ) );
Assert.Throws<CKException>( () => Console.Write( settings.GetRequired( "None" ) ) );
Assert.Throws<CKException>( () => Console.Write( settings.GetRequired<int>( "None" ) ) );
Assert.That( settings.Get<float>( "Test", -8 ), Is.EqualTo( -8.0 ) );
Assert.Throws<CKException>( () => settings.GetRequired<float>( "None" ) );
Assert.That( settings["Test"], Is.EqualTo( "3712" ) );
}
示例3: AppConfig
public AppConfig()
{
var appSettings = new AppSettings();
string baseApiUrl = appSettings.Get("BaseApiUrl","http://localhost:80/api/");
_serversToQuery = (List<string>)appSettings.GetList("ListOfServers");
_filterTerm = (List<string>)appSettings.GetList("FilterTermList");
//Fake two servers by talke localhost computer name and . that is local computer
// _serversToQuery = new List<string> { System.Environment.MachineName, "." };
}
示例4: Configure
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
//Configure User Defined REST Paths
//Routes
// .Add<Hello>("/hello")
// .Add<Hello>("/hello/{Name*}")
//.Add<Events>("/Events/")
//.Add<Events>("/Events/{Lag*}");
//Uncomment to change the default ServiceStack configuration
//SetConfig(new EndpointHostConfig {
//});
//Enable Authentication
//ConfigureAuth(container);
var appSettings = new AppSettings();
string baseApiUrl = appSettings.Get("BaseApiUrl","foo");
//Register all your dependencies
// container.Register<IJellybeanDispenser>(c => new VanillaJellybeanDispenser());
// container.Register(c => new SweetVendingMachine(c.Resolve<IJellybeanDispenser>()));
// container.Register(c => new SweetShop(c.Resolve<SweetVendingMachine>()));
// See more at: http://anthonysteele.co.uk/the-funq-ioc-container#sthash.ketDSF72.dpuf
container.Register<IAppConfig>(c=>new AppConfig());
container.Register<IEventRepository>(c=> new EventRepository());
container.Resolve<IEventRepository>().Config = container.Resolve<IAppConfig>();
// container.Register(c => new TodoRepository());
//Register a external dependency-free
container.Register<ICacheClient>(new MemoryCacheClient());
//Configure an alt. distributed persistent cache that survives AppDomain restarts. e.g Redis
//container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
//Set MVC to use the same Funq IOC as ServiceStack
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
}
示例5: ConfigureAuth
private void ConfigureAuth(Funq.Container container)
{
//Enable and register existing services you want this host to make use of.
//Look in Web.config for examples on how to configure your oauth proviers, e.g. oauth.facebook.AppId, etc.
var appSettings = new AppSettings();
//Register all Authentication methods you want to enable for this web app.
Plugins.Add(new AuthFeature(
() => new CustomUserSession(), //Use your own typed Custom UserSession type
new IAuthProvider[] {
new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
new TwitterAuthProvider(appSettings), //Sign-in with Twitter
new FacebookAuthProvider(appSettings), //Sign-in with Facebook
new BasicAuthProvider(), //Sign-in with Basic Auth
}));
//Provide service for new users to register so they can login with supplied credentials.
Plugins.Add(new RegistrationFeature());
//override the default registration validation with your own custom implementation
container.RegisterAs<CustomRegistrationValidator, IValidator<Registration>>();
//Create a DB Factory configured to access the UserAuth SQL Server DB
var connStr = appSettings.Get("SQLSERVER_CONNECTION_STRING", //AppHarbor or Local connection string
ConfigUtils.GetConnectionString("UserAuth"));
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(connStr, //ConnectionString in Web.Config
SqlServerOrmLiteDialectProvider.Instance) {
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
});
//Store User Data into the referenced SqlServer database
container.Register<IUserAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info
var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>(); //If using and RDBMS to persist UserAuth, we must create required tables
if (appSettings.Get("RecreateAuthTables", false))
authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else
authRepo.CreateMissingTables(); //Create only the missing tables
Plugins.Add(new RequestLogsFeature());
}
示例6: Configure
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
//Register Typed Config some services might need to access
var appSettings = new AppSettings();
Config = new AppConfig(appSettings);
container.Register(Config);
//Register all your dependencies:
//Register a external dependency-free
container.Register<ICacheClient>(new MemoryCacheClient());
//Configure an alt. distributed peristed cache that survives AppDomain restarts. e.g Redis
//container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
//Enable Authentication an Registration
ConfigureAuth(container);
////Create you're own custom User table
var userRepository = new MongoRepository(CreateMongodatabase("hta", new MongoServerSettings() { Server = new MongoServerAddress("localhost") }));
if (appSettings.Get("RecreateAuthTables", false))
userRepository.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else
userRepository.CreateMissingTables(); //Create only the missing tables
container.Register<IUserRepository>(userRepository);
container.Register<IAuthsRepository>(userRepository);
//Register application services
container.Register(new TodoRepository());
container.Register<ITwitterGateway>(new TwitterGateway());
//Configure Custom User Defined REST Paths for your services
ConfigureServiceRoutes();
//Change the default ServiceStack configuration
//const Feature disableFeatures = Feature.Jsv | Feature.Soap;
SetConfig(new EndpointHostConfig
{
//EnableFeatures = Feature.All.Remove(disableFeatures),
AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Html },
DebugMode = true, //Show StackTraces in service responses during development
});
//Set MVC to use the same Funq IOC as ServiceStack
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();
}
示例7: ConfigureAuth
private void ConfigureAuth(Container container)
{
var appSettings = new AppSettings();
Plugins.Add(new AuthFeature(
() => new AuthUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
new BasicAuthProvider(), //Sign-in with Basic Auth
}));
//Provide service for new users to register so they can login with supplied credentials.
Plugins.Add(new RegistrationFeature());
//override the default registration validation with your own custom implementation
//container.RegisterAs<CustomRegistrationValidator, IValidator<Registration>>();
//Store User Data into the referenced SqlServer database
container.Register<IUserAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
var userRep = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
//If using and RDBMS to persist UserAuth, we must create required tables
if (appSettings.Get("RecreateAuthTables", false))
userRep.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else
userRep.CreateMissingTables(); //Create only the missing tables
//Add a user for testing purposes
string hash;
string salt;
string password = "Nomvete";
new SaltedHash().GetHashAndSaltString(password, out hash, out salt);
userRep.CreateUserAuth(new UserAuth
{
Id = 1,
DisplayName = "DisplayName",
Email = "[email protected]",
UserName = "User1",
FirstName = "FirstName",
LastName = "LastName",
PasswordHash = hash,
Salt = salt,
}, password);
Plugins.Add(new RequestLogsFeature());
}