本文整理汇总了C#中IContainer.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.Resolve方法的具体用法?C# IContainer.Resolve怎么用?C# IContainer.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
Directory.CreateDirectory(_basePath);
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
_webDownloader = new Mock<IWebDownloader>();
_orchardServices = new StubOrchardServices();
((StubWorkContextAccessor.WorkContextImpl.StubSite) _orchardServices.WorkContext.CurrentSite).BaseUrl = "http://orchardproject.net";
_settings = new WarmupSettingsPart { Record = new WarmupSettingsPartRecord() };
_orchardServices.WorkContext.CurrentSite.ContentItem.Weld(_settings);
var builder = new ContainerBuilder();
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
builder.RegisterInstance(_orchardServices).As<IOrchardServices>();
builder.RegisterType<DefaultLockFileManager>().As<ILockFileManager>();
builder.RegisterType<WarmupUpdater>().As<IWarmupUpdater>();
builder.RegisterType<StubClock>().As<IClock>();
builder.RegisterType<WarmupReportManager>().As<IWarmupReportManager>();
builder.RegisterInstance(new ShellSettings { Name = "Default" }).As<ShellSettings>();
builder.RegisterInstance(_clock = new StubClock()).As<IClock>();
builder.RegisterInstance(_webDownloader.Object).As<IWebDownloader>();
_container = builder.Build();
_lockFileManager = _container.Resolve<ILockFileManager>();
_warmupUpdater = _container.Resolve<IWarmupUpdater>();
_reportManager = _container.Resolve<IWarmupReportManager>();
_warmupFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt");
_lockFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt.lock");
}
示例2: Init
protected override void Init(IContainer container)
{
dart = container.Resolve<Dart>();
dart.Position = new Vector2(
PhysicsConstants.PixelsToMeters(GraphicsDevice.Viewport.Width * -.4f),
PhysicsConstants.PixelsToMeters(GraphicsDevice.Viewport.Height * .4f));
dart.Size = PhysicsConstants.PixelsToMeters(new Vector2(60, 20));
var camera = container.Resolve<Camera>();
camera.TranslateCamera(
new Vector3(
GraphicsDevice.Viewport.Width / 2,
GraphicsDevice.Viewport.Height / 2, 0));
balloons = Enumerable.Range(0, 10)
.SelectMany(i => Enumerable.Range(0, 5)
.Select(j =>
{
var newBalloon = container.Resolve<Balloon>();
newBalloon.Position = new Vector2(
i * (BALLOON_RADIUS + BALLOON_OFFSET) + GLOBAL_OFFSET_X,
j * (BALLOON_RADIUS + BALLOON_OFFSET) + GLOBAL_OFFSET_Y);
newBalloon.Radius = BALLOON_RADIUS;
newBalloon.Size = PhysicsConstants.PixelsToMeters(new Vector2(40, 39));
return newBalloon;
}));
}
示例3: Run
public void Run(IContainer container)
{
var configuration = container.Resolve<Configuration>();
if (!configuration.OutputFolder.Exists) configuration.OutputFolder.Create();
var featureCrawler = container.Resolve<DirectoryTreeCrawler>();
GeneralTree<INode> features = featureCrawler.Crawl(configuration.FeatureFolder);
if (features == null)
{
log.Warn("No features found at {0}", configuration.FeatureFolder);
return;
}
ApplyTestResultsToFeatures(container, configuration, features);
var documentationBuilder = container.Resolve<IDocumentationBuilder>();
try
{
documentationBuilder.Build(features);
}
catch (Exception ex)
{
log.Error("Something went wrong while during generation: {0}", ex);
throw;
}
}
示例4: ConfigureAuth
public static void ConfigureAuth(IAppBuilder app, IContainer container)
{
var sessionState = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/api/token"),
Provider = container.Resolve<IOAuthAuthorizationServerProvider>(),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(sessionState.Timeout.TotalMinutes),
AllowInsecureHttp = true
});
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
{
Provider = container.Resolve<IOAuthBearerAuthenticationProvider>(),
//override the token deserialization to be able to capture the properties
AccessTokenProvider = new AuthenticationTokenProvider()
{
OnReceive = (c) =>
{
c.DeserializeTicket(c.Token);
//check if invalid bearer token received
if (c.Ticket != null)
{
c.OwinContext.Environment["oauth.Properties"] = c.Ticket.Properties;
}
}
}
});
}
示例5: ConfigureContainer
protected override void ConfigureContainer( IContainer container )
{
this.CoreConfig = container.Resolve<INGinConfig>();
// create temporary builder for log manager
ContainerBuilder builder = new ContainerBuilder();
// register and build log manager first
this.ConfigureLogManager( builder );
builder.Build( container );
ILogManager logManager = container.Resolve<ILogManager>();
// log message
logManager.Trace( Namespace.LoggerName, LogLevel.Information, "Configuring module: {0}...", typeof( CoreModule ).FullName );
// create new builder for other core components
builder = new ContainerBuilder();
// configure core services
this.ConfigureConfigManager( builder, logManager );
this.ConfigureDependencyResolver( builder, logManager );
this.ConfigurePluginManager( builder, logManager );
// build to container
builder.Build( container );
this.ConfigureCustomConfigDataTypes( container, logManager );
base.ConfigureContainer( container );
}
示例6: QueueProcessor
public QueueProcessor(IContainer factory)
{
_factory = factory;
_itemProcessor = _factory.Resolve<IItemProcessor>();
_queueItemDAL = _factory.Resolve<IQueueItemDAL>();
}
示例7: GetRegistrationFor
/// <summary>
/// Gets a registration for some contract type.
/// </summary>
/// <param name="contractType">The contract type.</param>
/// <param name="container">The container.</param>
/// <returns><value>The registration item</value> if this source can handle it, otherwise <value>null</value>.</returns>
public RegistrationItem GetRegistrationFor(Type contractType, IContainer container)
{
Type[] genericArguments = contractType.GetGenericArguments();
// Get the Registration for the open generic type.
RegistrationItem openGenericTypeRegistration =
this._registrationContainer
.Registrations[contractType.GetGenericTypeDefinition()];
// Register closed generic type on-the-fly.
Type implementationType = openGenericTypeRegistration.ImplementationType.MakeGenericType(genericArguments);
var closedGenericRegistration = new RegistrationItem(contractType)
{
Activator = new ReflectionActivator(
implementationType,
container.Resolve<IConstructorSelector>(),
container.Resolve<IArgumentCollector>()
),
ImplementationType = implementationType
};
var fluentRegistration = new FluentRegistration(closedGenericRegistration);
fluentRegistration.ControlledBy(openGenericTypeRegistration.Lifecycle.GetType());
return closedGenericRegistration;
}
示例8: InitObjects
private void InitObjects(IContainer container)
{
_server = (McServer)container.Resolve<IServer>();
_config = container.Resolve<IMcManageConfig>();
_config.Load("config.ini",Properties.Resources.defaultconfig);
_coreMap = container.Resolve<FilterMap>();
}
示例9: Init
public void Init() {
string databaseFileName = Path.GetTempFileName();
IDataServicesProviderFactory dataServicesProviderFactory = new DataServicesProviderFactory(new[] {
new Meta<CreateDataServicesProvider>(
(dataFolder, connectionString) => new SqlCeDataServicesProvider(dataFolder, connectionString),
new Dictionary<string, object> {{"ProviderName", "SqlCe"}})
});
var builder = new ContainerBuilder();
builder.RegisterInstance(new ShellBlueprint());
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataTablePrefix = "Test", DataProvider = "SqlCe" });
builder.RegisterInstance(dataServicesProviderFactory).As<IDataServicesProviderFactory>();
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(Path.GetDirectoryName(databaseFileName))).As<IAppDataFolder>();
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
builder.RegisterType<CompositionStrategy>().As<ICompositionStrategy>();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<SchemaCommandGenerator>().As<ISchemaCommandGenerator>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
_container = builder.Build();
_extensionManager = _container.Resolve<IExtensionManager>();
_schemaCommandGenerator = _container.Resolve<ISchemaCommandGenerator>();
}
示例10: Init
public void Init(IEnumerable<Type> dataMigrations) {
var builder = new ContainerBuilder();
_folders = new StubFolders();
var contentDefinitionManager = new Mock<IContentDefinitionManager>().Object;
builder.RegisterInstance(new ShellSettings { DataTablePrefix = "TEST_"});
builder.RegisterType<SqlServerDataServicesProvider>().As<IDataServicesProvider>();
builder.RegisterType<DataServicesProviderFactory>().As<IDataServicesProviderFactory>();
builder.RegisterType<NullInterpreter>().As<IDataMigrationInterpreter>();
builder.RegisterInstance(_folders).As<IExtensionFolders>();
builder.RegisterInstance(contentDefinitionManager).As<IContentDefinitionManager>();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<DataMigrationManager>().As<IDataMigrationManager>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>().As<ITransactionManager>();
foreach(var type in dataMigrations) {
builder.RegisterType(type).As<IDataMigration>();
}
_container = builder.Build();
_container.Resolve<IExtensionManager>();
_dataMigrationManager = _container.Resolve<IDataMigrationManager>();
_repository = _container.Resolve<IRepository<DataMigrationRecord>>();
_transactionManager = _container.Resolve<ITransactionManager>();
InitDb();
}
示例11: CreateShell
internal Shell CreateShell(BrowseForRepositoryEvent browseForRepositoryEvent, Arguments arguments)
{
var builder = new Autofac.ContainerBuilder();
ChorusUIComponentsInjector.Inject(builder, _projectPath, SyncUIFeatures.Advanced);
builder.RegisterInstance(browseForRepositoryEvent).As<BrowseForRepositoryEvent>().SingleInstance();
//For now, we like the idea of just using the login name. But
//this allows someone to override that in the ini (which would be for all users of this machine, then)
builder.Register<IChorusUser>(c => new ChorusUser(c.Resolve<HgRepository>().GetUserNameFromIni(new NullProgress(), System.Environment.UserName)));
builder.RegisterType<Shell>();
if(arguments!=null)
{
builder.RegisterInstance(arguments);
Synchronizer.s_testingDoNotPush = arguments.DontPush; //hack, at this point it would take a lot of plumbing
//to get this properly to any synchronizer that is created. Can be fixed if/when we go to the
//autofac generated factor approach
}
_container = builder.Build();
var shell= _container.Resolve<Shell>();
var system = new ChorusSystem(_projectPath);
system.Init(string.Empty);
shell.AddPage("Review", system.WinForms.CreateHistoryPage());
shell.AddPage("Notes", system.WinForms.CreateNotesBrowser());
shell.AddPage("Send/Receive", _container.Resolve<SyncPanel>());
shell.AddPage("Settings", _container.Resolve<SettingsView>());
shell.AddPage("Troubleshooting", _container.Resolve<TroubleshootingView>());
return shell;
}
示例12: InitDependencyResolvers
private void InitDependencyResolvers()
{
var appName = ConfigurationManager.AppSettings["AppName"];
var configPath = ConfigurationManager.AppSettings["ConfigPath"];
var environment = ConfigurationManager.AppSettings["Environment"];
if (!string.IsNullOrEmpty(appName) && !string.IsNullOrEmpty(configPath) &&
!String.IsNullOrEmpty(environment))
{
var appParams = new List<NamedParameter>
{
new NamedParameter("configPath", configPath),
new NamedParameter("appName", appName),
new NamedParameter("environment", environment)
};
_containerBuilder.RegisterType<AppSetting>().As<IAppSetting>().SingleInstance().WithParameters(appParams);
}
else
{
_containerBuilder.RegisterType<AppSetting>().As<IAppSetting>().SingleInstance();
}
_containerBuilder.RegisterType<Log4NetServiceFactory>().As<ILoggingServiceFactory>().SingleInstance();
_containerBuilder.RegisterType<Events.EventService>().As<IEventService>();
_containerBuilder.RegisterType<Events.EventServiceFactory>().As<IEventServiceFactory>();
_containerBuilder.RegisterType<ReturnEventProcessor>().Keyed<IEventProcessor>(EventCategory.Return);
_containerBuilder.RegisterType<ProductEventProcessor>().Keyed<IEventProcessor>(EventCategory.Product);
_containerBuilder.RegisterType<OrderEventProcessor>().Keyed<IEventProcessor>(EventCategory.Order);
_containerBuilder.RegisterType<ApplicationEventProcessor>().Keyed<IEventProcessor>(EventCategory.Application);
_containerBuilder.RegisterType<CustomerAccountEventProcessor>().Keyed<IEventProcessor>(EventCategory.CustomerAccount);
_containerBuilder.RegisterType<DiscountEventProcessor>().Keyed<IEventProcessor>(EventCategory.Discount);
InitializeContainer(_containerBuilder);
Container = _containerBuilder.Build();
LogManager.LoggingService = Container.Resolve<ILoggingServiceFactory>().GetLoggingService();
var appSetting = Container.Resolve<IAppSetting>();
if (!string.IsNullOrEmpty(appSetting.ApplicationId) && !string.IsNullOrEmpty(appSetting.SharedSecret))
{
if (!string.IsNullOrEmpty(appSetting.BaseUrl))
MozuConfig.BaseAppAuthUrl = appSetting.BaseUrl;
var appAuthenticator = AppAuthenticator.InitializeAsync(new AppAuthInfo { ApplicationId = appSetting.ApplicationId, SharedSecret = appSetting.SharedSecret }).Result;
}
PostInitialize();
}
示例13: Init
public void Init() {
var builder = new ContainerBuilder();
builder.RegisterType<ResourceManager>().As<IResourceManager>();
builder.RegisterType<TestManifestProvider>().As<IResourceManifestProvider>().SingleInstance();
_container = builder.Build();
_resourceManager = _container.Resolve<IResourceManager>();
_testManifest = _container.Resolve<IResourceManifestProvider>() as TestManifestProvider;
}
示例14: TestInitialize
public virtual void TestInitialize()
{
_container = Bootstrapper.InitializeContainer();
RetryExecuterMock = new Mock<IRetryExecuter>();
UserRepositoryMock = new Mock<IUserServices>();
SecurityHelperMock = new Mock<ISecurityHelper>();
MappingEngine = _container.Resolve<IMapper>();
DbContext = (WebApiSeedDbContext)_container.Resolve<IDbContext>();
}
示例15: QueueItemProcessor
public QueueItemProcessor(IContainer factory)
{
_factory = factory;
_earnedBadgeDAL = _factory.Resolve<IEarnedBadgeCollectionDAL>();
_queueItemDAL = _factory.Resolve<IQueueItemDAL>();
_queueEventLogDAL = _factory.Resolve<IQueueEventLogDAL>();
_publishers = _factory.Resolve<IEnumerable<IPublisher>>();
}