本文整理汇总了C#中Funq.Container类的典型用法代码示例。如果您正苦于以下问题:C# Container类的具体用法?C# Container怎么用?C# Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于Funq命名空间,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig
{
UseBclJsonSerializers = true,
});
}
示例2: Configure
public override void Configure(Container container)
{
HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath;
HostConfig.Instance.MapExceptionToStatusCode = new Dictionary<Type, int>
{
{typeof (InvalidOperationException), 422},
{typeof (ResourceNotFoundException), 404},
{typeof (FileNotFoundException), 404},
{typeof (DirectoryNotFoundException), 404},
{typeof (Implementations.Security.AuthenticationException), 401}
};
HostConfig.Instance.DebugMode = true;
HostConfig.Instance.LogFactory = LogManager.LogFactory;
// The Markdown feature causes slow startup times (5 mins+) on cold boots for some users
// Custom format allows images
HostConfig.Instance.EnableFeatures = Feature.Csv | Feature.Html | Feature.Json | Feature.Jsv | Feature.Metadata | Feature.Xml | Feature.CustomFormat;
container.Adapter = _containerAdapter;
Plugins.Add(new SwaggerFeature());
Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization"));
//Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
// new SessionAuthProvider(_containerAdapter.Resolve<ISessionContext>()),
//}));
HostContext.GlobalResponseFilters.Add(new ResponseFilter(_logger).FilterResponse);
}
示例3: Install
public void Install(Container container)
{
var userRepo = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRepo);
//HACK: Add default users
var users = new[]
{
new User("Admin", "AdminPassword"),
new User("cyberzed", "cyberzed")
};
foreach (var user in users)
{
string hash;
string salt;
new SaltedHash().GetHashAndSaltString(user.Password, out hash, out salt);
userRepo.CreateUserAuth(
new UserAuth
{
DisplayName = user.Username,
UserName = user.Username,
PasswordHash = hash,
Salt = salt
},
user.Password);
}
}
示例4: Configure
public override void Configure(Container container)
{
JsConfig.EmitCamelCaseNames = true;
Plugins.Add(new RazorFormat());
//Comment out 2 lines below to change to use local FileSystem instead of S3
var s3Client = new AmazonS3Client(AwsConfig.AwsAccessKey, AwsConfig.AwsSecretKey, RegionEndpoint.USEast1);
VirtualFiles = new S3VirtualPathProvider(s3Client, AwsConfig.S3BucketName, this);
container.Register<IPocoDynamo>(c => new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()));
var db = container.Resolve<IPocoDynamo>();
db.RegisterTable<Todos.Todo>();
db.RegisterTable<EmailContacts.Email>();
db.RegisterTable<EmailContacts.Contact>();
db.InitSchema();
//AWS Auth
container.Register<ICacheClient>(new DynamoDbCacheClient(db, initSchema:true));
container.Register<IAuthRepository>(new DynamoDbAuthRepository(db, initSchema:true));
Plugins.Add(CreateAuthFeature());
//EmailContacts
ConfigureSqsMqServer(container);
ConfigureEmailer(container);
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(EmailContacts.CreateContact).Assembly);
}
示例5: Configure
public override void Configure(Container container)
{
Plugins.Add(new RazorFormat());
Plugins.Add(new MsgPackFormat());
Plugins.Add(new SwaggerFeature { UseBootstrapTheme = true });
typeof(SwaggerResources)
.AddAttributes(new RestrictAttribute { VisibilityTo = RequestAttributes.None });
typeof(SwaggerResource)
.AddAttributes(new RestrictAttribute { VisibilityTo = RequestAttributes.None });
var metadata = (MetadataFeature)Plugins.First(x => x is MetadataFeature);
metadata.IndexPageFilter = page => {
page.OperationNames.Sort((x,y) => y.CompareTo(x));
};
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
InitData(container);
SetConfig(new HostConfig {
DebugMode = true,
});
this.CustomErrorHttpHandlers[HttpStatusCode.ExpectationFailed] = new RazorHandler("/expectationfailed");
}
示例6: Configure
/// <summary>
/// Configure the Web Application host.
/// </summary>
/// <param name="container">The IoC container.</param>
public override void Configure(Container container)
{
// Configure ServiceStack host
ConfigureHost(container);
// Configure JSON serialization properties
ConfigureSerialization(container);
// Configure application settings and configuration parameters
ConfigureApplication(container);
// Configure database schema synchronization
ConfigureDataSchema(container);
// Configure ServiceStack database connections
ConfigureDataConnection(container);
// Configure caching mechanism
ConfigureCache(container);
// Configure ServiceStack Authentication plugin
ConfigureUserAuth(container);
// Configure ServiceStack Fluent Validation plugin
ConfigureValidation(container);
// Configure ServiceStack Razor views
ConfigureView(container);
// Configure various system tools / features
ConfigureTools(container);
}
示例7: Configure
public override void Configure(Container container)
{
LogManager.LogFactory = new ConsoleLogFactory();
SetConfig(new HostConfig
{
DebugMode = true,
EmbeddedResourceSources = { Assembly.GetExecutingAssembly() },
});
Plugins.Add(new RazorFormat
{
LoadFromAssemblies = { typeof(RockstarsService).Assembly }
});
Plugins.Add(new PostmanFeature());
Plugins.Add(new CorsFeature());
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
{
db.CreateTableIfNotExists<Rockstar>();
db.InsertAll(RockstarsService.SeedData);
}
this.CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/notfound");
this.CustomErrorHttpHandlers[HttpStatusCode.Unauthorized] = new RazorHandler("/login");
}
示例8: RegisterRepositories
private static void RegisterRepositories(Container container)
{
container.Register<IUserTokenRepository>(
c => new UserTokenRecordRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IServiceProviderRepository>(
c => new ServiceProviderRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IAuthProviderFactory>(
c => new AuthProviderFactory(c.Resolve<IEnumerable<IAuthProviderInstance>>()));
container.Register<IApplicationRepository>(
c => new ApplicationRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IApplicationServiceRepository>(
c => new ApplicationServiceRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IAccountApplicationRepository>(
c => new AccountApplicationRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IAccountRepository>(
c => new AccountRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IAccountUserRepository>(
c => new AccountUserRepository(c.Resolve<IDataConnectionProvider>()));
container.Register<IUserRepository>(
c => new UserRepository(c.Resolve<IDataConnectionProvider>()));
}
示例9: Configure
public override void Configure(Container container)
{
Plugins.Add(new SwaggerFeature());
Plugins.Add(new RazorFormat());
Plugins.Add(new RequestLogsFeature());
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(ContactsServices).Assembly);
container.Register<IDbConnectionFactory>(
c => new OrmLiteConnectionFactory("db.sqlite", SqliteDialect.Provider) {
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
});
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<Email>();
db.DropAndCreateTable<Contact>();
db.Insert(new Contact { Name = "Kurt Cobain", Email = "[email protected]", Age = 27 });
db.Insert(new Contact { Name = "Jimi Hendrix", Email = "[email protected]", Age = 27 });
db.Insert(new Contact { Name = "Michael Jackson", Email = "[email protected]", Age = 50 });
}
UseDbEmailer(container);
//UseSmtpEmailer(container); //Uncomment to use SMTP instead
//ConfigureRabbitMqServer(container); //Uncomment to start accepting requests via Rabbit MQ
}
示例10: Configure
/// <summary>
/// Application specific configuration
/// This method should initialize any IoC resources utilized by your web service classes.
/// </summary>
/// <param name="container"></param>
public override void Configure(Container container)
{
Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new CustomAuthentication(), }));
container.Register<ICacheClient>(new MemoryCacheClient());
var userRepository = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRepository);
}
示例11: Main
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var container = new Container();
Tepeyac.Funq.Registry.Register(container);
container.Register<IFiber>("GuiFiber", c => c.Resolve<IFiber>());
/*
container.Register<IFiber>("GuiFiber", c =>
{
var executor =
c.Resolve<IExecutor>() ??
new Executor();
var invoke = new SynchronizeInvoke(new WindowsFormsSynchronizationContext());
var fiber = new FormFiber(invoke, executor);
fiber.Start();
return fiber;
});
*/
container.Register<IBurritoDayView>(c =>
new BurritoDayView(c));
container.Resolve<IBurritoDayView>();
Application.Run();
}
示例12: Configure
public static void Configure(Container container, PhoneApplicationFrame root)
{
container.Register<IJiraService>(c => new JiraService{Store = c.Resolve<IDocumentStore>()});
container.Register<IScheduler>(c => new Scheduler());
container.Register(c => new SignInCommandHandler{Bus = c.Resolve<IBus>()});
container.Register(c => new SyncHandler{Bus = c.Resolve<IBus>(), Jira = c.Resolve<IJiraService>()});
container.Register(
c => new SyncProjectHandler
{
Bus = c.Resolve<IBus>(),
Store = c.Resolve<IDocumentStore>(),
Jira = c.Resolve<IJiraService>(),
Scheduler = c.Resolve<IScheduler>()
});
container.Register(c => new SyncNewlyDiscoveredProjectsByDefaultHandler {Bus = c.Resolve<IBus>()});
container.Register(c => new ProfileLoggedInEventHandler { Store = c.Resolve<IDocumentStore>() });
var bus = container.Resolve<IBus>();
bus.RegisterHandler<SignInCommandHandler, SignInCommand>();
bus.RegisterHandler<SyncHandler, ApplicationLoadedEvent>();
bus.RegisterHandler<ProfileLoggedInEventHandler, LoggedInEvent>();
bus.RegisterHandler<SyncHandler, LoggedInEvent>();
bus.RegisterHandler<SyncProjectHandler, ProjectsDiscoveredEvent>();
bus.RegisterHandler<SyncProjectHandler, SyncProjectCommand>();
bus.RegisterHandler<SyncNewlyDiscoveredProjectsByDefaultHandler, DiscoveredNewProjectEvent>();
}
示例13: StatusItemBurritoDayView
public StatusItemBurritoDayView(Container container)
{
this.menu = new NSMenu();
this.menu.AddItem(this.refreshMenuItem);
this.menu.AddItem(this.launchMenuItem);
this.menu.AddItem(NSMenuItem.SeparatorItem);
this.menu.AddItem(this.durationMenuItem);
this.menu.AddItem(this.locationMenuItem);
this.menu.AddItem(this.separatorMenuItem);;
this.menu.AddItem(this.dismissMenuitem);
this.menu.AddItem(this.quitMenuItem);
this.launchMenuItem.Activated += delegate {
var handler = this.urlActivated;
if (handler != null)
{
handler(this, "http://isitburritoday.com");
}
};
this.quitMenuItem.Activated += (sender, e) =>
NSApplication.SharedApplication.Terminate(sender as NSObject);
this.presenters = new IDisposable[]
{
container.Resolve<BurritoDayPresenter, IBurritoDayView>(this),
container.Resolve<UrlActivationPresenter, IUrlActivationView>(this),
};
}
示例14: Configure
public override void Configure(Container container)
{
//Permit modern browsers (e.g. Firefox) to allow sending of any REST HTTP Method
base.SetConfig(new EndpointHostConfig
{
GlobalResponseHeaders =
{
{ "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
},
});
container.Register<IResourceManager>(new ConfigurationResourceManager());
container.Register(c => new ExampleConfig(c.Resolve<IResourceManager>()));
var appConfig = container.Resolve<ExampleConfig>();
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(
appConfig.ConnectionString.MapHostAbsolutePath(),
SqliteOrmLiteDialectProvider.Instance));
ConfigureDatabase.Init(container.Resolve<IDbConnectionFactory>());
//register different cache implementations depending on availability
const bool hasRedis = false;
if (hasRedis)
container.Register<ICacheClient>(c => new BasicRedisClientManager());
else
container.Register<ICacheClient>(c => new MemoryCacheClient());
log.InfoFormat("AppHost Configured: " + DateTime.Now);
}
示例15: Configure
public override void Configure(Container container)
{
this.RequestFilters.Add((req, res, dto) =>
{
var requestFilter = dto as RequestFilter;
if (requestFilter != null)
{
res.StatusCode = requestFilter.StatusCode;
if (!requestFilter.HeaderName.IsNullOrEmpty())
{
res.AddHeader(requestFilter.HeaderName, requestFilter.HeaderValue);
}
res.Close();
}
var secureRequests = dto as IRequiresSession;
if (secureRequests != null)
{
res.ReturnAuthRequired();
}
});
this.Container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(
"~/App_Data/db.sqlite".MapHostAbsolutePath(),
SqliteOrmLiteDialectProvider.Instance));
this.Container.Register<ICacheClient>(new MemoryCacheClient());
var dbFactory = this.Container.Resolve<IDbConnectionFactory>();
dbFactory.Exec(dbCmd => dbCmd.CreateTable<Movie>(true));
var resetMovies = this.Container.Resolve<ResetMoviesService>();
resetMovies.Post(null);
}