本文整理汇总了C#中Funq.Container.RegisterAs方法的典型用法代码示例。如果您正苦于以下问题:C# Container.RegisterAs方法的具体用法?C# Container.RegisterAs怎么用?C# Container.RegisterAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Funq.Container
的用法示例。
在下文中一共展示了Container.RegisterAs方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public override void Configure(Container container)
{
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
container.Resolve<ICacheClient>().InitSchema();
}
示例2: Configure
public override void Configure(Container container)
{
if (container == null)
throw new ArgumentNullException("container");
// Makes the a disk repository available to service implementations
container.RegisterAs<DiskRepository,IDiskRepository>();
#if DEBUG
Trace.Listeners.Add(new ConsoleTraceListener(true));
#endif
}
示例3: UseSmtpEmailer
private static void UseSmtpEmailer(Container container)
{
var appSettings = new AppSettings();
//Use 'SmtpConfig' appSetting in Web.config if it exists otherwise use default config below:
container.Register(appSettings.Get("SmtpConfig",
new SmtpConfig {
Host = "smtphost",
Port = 587,
UserName = "ADD_USERNAME",
Password = "ADD_PASSWORD"
}));
container.RegisterAs<SmtpEmailer, IEmailer>().ReusedWithin(ReuseScope.Request);
}
示例4: Configure
public override void Configure(Container container)
{
LogManager.LogFactory = new ConsoleLogFactory();
IAppSettings appSettings = new DictionarySettings(
new Dictionary<string, string>
{
{ "backup.history", "5" },
{ "auth.api-keys", "1337"}
});
container.Register(c => appSettings);
container.RegisterAutoWired<IISManager>();
container.RegisterAs<AppSettingsApiKeyValidator, IApiKeyValidator>();
Plugins.Add(new RequestLogsFeature { RequiredRoles = null });
}
示例5: ConfigureEmailer
private void ConfigureEmailer(Container container)
{
//If SmtpConfig exists, use real SMTP Emailer otherwise use simulated DbEmailer
var smtpConfig = AppSettings.Get<EmailContacts.SmtpConfig>("SmtpConfig");
if (smtpConfig != null)
{
container.Register(smtpConfig);
container.RegisterAs<EmailContacts.SmtpEmailer, EmailContacts.IEmailer>().ReusedWithin(ReuseScope.Request);
}
else
{
container.RegisterAs<EmailContacts.DbEmailer, EmailContacts.IEmailer>().ReusedWithin(ReuseScope.Request);
}
}
示例6: ConfigureCache
/// <summary>
/// Configure caching mechanism
/// </summary>
/// <param name="container">The DI / IoC container.</param>
private void ConfigureCache(Container container)
{
// User OrmLite SQL database-backed persistent cache
container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
}
示例7: ConfigureAuth
private void ConfigureAuth(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 providers, 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 DigestAuthProvider(appSettings), //Sign-in with Digest Auth
new BasicAuthProvider(), //Sign-in with Basic Auth
new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
new YahooOpenIdOAuthProvider(appSettings), //Sign-in with Yahoo OpenId
new OpenIdOAuthProvider(appSettings), //Sign-in with Custom OpenId
new GoogleOAuth2Provider(appSettings), //Sign-in with Google OAuth2 Provider
new LinkedInOAuth2Provider(appSettings), //Sign-in with LinkedIn OAuth2 Provider
}));
#if HTTP_LISTENER
//Required for DotNetOpenAuth in HttpListener
OpenIdOAuthProvider.OpenIdApplicationStore = new InMemoryOpenIdApplicationStore();
#endif
//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<Register>>();
//Store User Data into the referenced SqlServer database
container.Register<IAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info
var authRepo = (OrmLiteAuthRepository)container.Resolve<IAuthRepository>(); //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());
}
示例8: UseDbEmailer
private static void UseDbEmailer(Container container)
{
container.RegisterAs<DbEmailer, IEmailer>().ReusedWithin(ReuseScope.Request);
}
示例9: ConfigureAuth
private void ConfigureAuth(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 providers, 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() {GalleryService = container.Resolve<IGalleryService>(), UserService = container.Resolve<IUserService>()},
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 DigestAuthProvider(appSettings), //Sign-in with Digest Auth
new BasicAuthProvider(), //Sign-in with Basic Auth
new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
new YahooOpenIdOAuthProvider(appSettings), //Sign-in with Yahoo OpenId
new OpenIdOAuthProvider(appSettings), //Sign-in with Custom OpenId
}));
//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 = AppConfig.ConnectionString;
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());
}
示例10: Compose
public void Compose(Container container)
{
container.RegisterAs<PersonRepository, IPersonRepository>();
}
示例11: Start
/**/
public static void Start()
{
var store = new DocumentStore
{
Url = "http://localhost:8080/",
DefaultDatabase = "svcStack"
}
.Initialize();
new AppHost(store).Init();
}
public override void Configure(Container container)
{
var appSettings = new AppSettings();
AppConfig = new AppConfig(appSettings);
container.Register(AppConfig);
container.Register<ICacheClient>(new MemoryCacheClient());
//Set JSON web services to return idiomatic JSON camelCase properties
JsConfig.EmitCamelCaseNames = true;
Plugins.Add(new SwaggerFeature());
//Configure User Defined REST Paths
Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name*}")
//Custom services for this application
.Add<Users>("/users/{UserIds}")
.Add<UserProfile>("/profile");
//Uncomment to change the default ServiceStack configuration
//SetConfig(new EndpointHostConfig {
//});
//Enable Authentication
ConfigureAuth(container);
//Register all your dependencies
container.Register(new TodoRepository());
//Set MVC to use the same Funq IOC as ServiceStack
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
}
/* Uncomment to enable ServiceStack Authentication and CustomUserSession*/
private void ConfigureAuth(Container container)
{
var appSettings = new AppSettings();
//Default route: /auth/{provider}
Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings),
//new FacebookAuthProvider(appSettings),
//new TwitterAuthProvider(appSettings),
//new BasicAuthProvider(appSettings),
new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
new YahooOpenIdOAuthProvider(appSettings), //Sign-in with Yahoo OpenId
new OpenIdOAuthProvider(appSettings),
}));
//Default route: /register
Plugins.Add(new RegistrationFeature());
//Requires ConnectionString configured in Web.Config
container.RegisterAs<CustomRegistrationValidator, IValidator<Registration>>();
container.Register<IUserAuthRepository>(c => new RavenUserAuthRepository(Store));
CreateAdminIfNotPresent(container);
}