本文整理汇总了C#中ILifetimeScope.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# ILifetimeScope.Resolve方法的具体用法?C# ILifetimeScope.Resolve怎么用?C# ILifetimeScope.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILifetimeScope
的用法示例。
在下文中一共展示了ILifetimeScope.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
protected override void Resolve(ILifetimeScope container) {
_compositionStrategy = container.Resolve<CompositionStrategy>();
_compositionStrategy.Logger = container.Resolve<ILogger>();
var alphaExtension = new ExtensionDescriptor {
Id = "Alpha",
Name = "Alpha",
ExtensionType = "Module"
};
var alphaFeatureDescriptor = new FeatureDescriptor {
Id = "Alpha",
Name = "Alpha",
Extension = alphaExtension
};
var betaFeatureDescriptor = new FeatureDescriptor {
Id = "Beta",
Name = "Beta",
Extension = alphaExtension,
Dependencies = new List<string> {
"Alpha"
}
};
alphaExtension.Features = new List<FeatureDescriptor> {
alphaFeatureDescriptor,
betaFeatureDescriptor
};
_availableExtensions = new[] {
alphaExtension
};
_installedFeatures = new List<Feature> {
new Feature {
Descriptor = alphaFeatureDescriptor,
ExportedTypes = new List<Type> {
typeof(AlphaDependency)
}
},
new Feature {
Descriptor = betaFeatureDescriptor,
ExportedTypes = new List<Type> {
typeof(BetaDependency)
}
}
};
_loggerMock.Setup(x => x.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
_extensionManager.Setup(x => x.AvailableExtensions()).Returns(() => _availableExtensions);
_extensionManager.Setup(x => x.AvailableFeatures()).Returns(() =>
_extensionManager.Object.AvailableExtensions()
.SelectMany(ext => ext.Features)
.ToReadOnlyCollection());
_extensionManager.Setup(x => x.LoadFeatures(It.IsAny<IEnumerable<FeatureDescriptor>>())).Returns(() => _installedFeatures);
}
示例2: RequestStartup
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
{
// No registrations should be performed in here, however you may
// resolve things that are needed during request startup.
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration()
{
RedirectUrl = "~/account/login",
UserMapper = container.Resolve<IUserMapper>(),
});
pipelines.BeforeRequest.AddItemToEndOfPipeline(c =>
{
if (c.CurrentUser.IsAuthenticated())
{
container.Resolve<ITenantContext>().SetTenantId(c.CurrentUser.AsAuthenticatedUser().Id, c.CurrentUser.HasClaim("Admin"));
c.ViewBag.UserName = c.CurrentUser.AsAuthenticatedUser().FullName;
c.ViewBag.IsAdmin = c.CurrentUser.HasClaim("Admin");
}
else
container.Resolve<ITenantContext>().SetTenantId(null, false);
return null;
});
}
示例3: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
StaticConfiguration.DisableErrorTraces = false;
// Enable memory sessions, and secure them against session hijacking
pipelines.EnableInProcSessions();
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => {
var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
return antiSessionHijackLogic.InterceptHijackedSession(ctx.Request);
});
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => {
var antiSessionHijackLogic = container.Resolve<IAntiSessionHijackLogic>();
antiSessionHijackLogic.ProtectResponseFromSessionHijacking(ctx);
});
// Load the user from the AspNet session. If one is found, create a Nancy identity and assign it.
pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx => {
var identityAssigner = container.Resolve<INancyIdentityFromContextAssigner>();
identityAssigner.AssignNancyIdentityFromContext(ctx);
return null;
});
pipelines.OnError = pipelines.OnError
+ ErrorPipelines.HandleModelBindingException()
+ ErrorPipelines.HandleRequestValidationException()
+ ErrorPipelines.HandleSecurityException();
base.ApplicationStartup(container, pipelines);
}
示例4: OnStartScope
public void OnStartScope(ILifetimeScope scope)
{
var defaultFactoryMapper = scope.Resolve<IFactoryMapper>() as DefaultFactoryMapper;
defaultFactoryMapper?.PerformAutomaticMappingByAttribute();
var storageMap = scope.Resolve<IConfigurationToExtentStorageMapper>() as ManualConfigurationToExtentStorageMapper;
storageMap?.PerformMappingForConfigurationOfExtentLoaders();
}
示例5: PingHub
public PingHub(ILifetimeScope lifetimeScope)
{
// Create a lifetime scope for this hub instance.
_hubLifetimeScope = lifetimeScope.BeginLifetimeScope();
// Resolve the dependencies from the hub lifetime scope (unfortunately, service locator style).
_bar = _hubLifetimeScope.Resolve<IBar>();
_foo = _hubLifetimeScope.Resolve<IFoo>();
}
示例6: ResetState
public INavigationService ResetState()
{
using (var oldScope = currentScope)
{
currentScope = rootScope.BeginLifetimeScope();
mainWindow.DataContext = currentScope.Resolve<IMainWindowViewModel>();
return currentScope.Resolve<INavigationService>();
}
}
示例7: CommonHub
public CommonHub(ILifetimeScope lifetimeScope)
{
// Create a lifetime scope for the hub.
_hubLifetimeScope = lifetimeScope.BeginLifetimeScope();
// Resolve dependencies from the hub lifetime scope
_documentService = _hubLifetimeScope.Resolve<IDocumentsService>(); // singleton
_tableService = _hubLifetimeScope.Resolve<ITableService>(); // singleton
_counterService = _hubLifetimeScope.Resolve<IDistributedCounter>(); // singleton
}
示例8: EnsureProfileProperties
private void EnsureProfileProperties(ILifetimeScope scope, ITargetingProfileConfig config, SPSite site)
{
var logger = scope.Resolve<ILogger>();
var userProfilePropertyHelper = scope.Resolve<IUserProfilePropertyHelper>();
foreach (var userProfilePropertyInfo in config.UserProfileProperties)
{
logger.Info("Ensuring profile property '{0}'", userProfilePropertyInfo.Name);
userProfilePropertyHelper.EnsureProfileProperty(site, userProfilePropertyInfo);
}
}
示例9: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
var generator = container.Resolve<IFrankengenerator>();
var store = container.Resolve<IFrankenstore>();
var rootPathProvider = container.Resolve<IRootPathProvider>();
var wikiSourcePathSetting = container.Resolve<WikiSourcePathSetting>();
var sourcePath = Path.Combine(rootPathProvider.GetRootPath(), wikiSourcePathSetting);
generator.GenerateFromSource(sourcePath, store);
}
示例10: ApplicationStartup
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
var customPipelines = new PipelinesBuilder()
.WithErrorHandling(container.Resolve<IResponseNegotiator>(), container.Resolve<INancyErrorMap>())
.Build();
pipelines.BeforeRequest += customPipelines.BeforeRequest;
pipelines.AfterRequest += customPipelines.AfterRequest;
pipelines.OnError += customPipelines.OnError;
base.ApplicationStartup(container, pipelines);
}
示例11: MainWindow
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
_container = ContainerHost.Container;
_deviceService = _container.Resolve<IDeviceService>();
_userService = _container.Resolve<IUserService>();
this.Register<LogoutAndShowMainMessage>(_reshowThis);
XDispatcher.Dispatcher = Dispatcher;
}
示例12: MainMenu
public MainMenu ()
{
InitializeComponent ();
Master = _master = new MainMenuView ();
_scope = App.AutoFacContainer.BeginLifetimeScope ();
var mainNav = new NavigationPage (_scope.Resolve<DashboardPage>());
//var msg = new NotificationMessage<IDictionary<string, int>>(new Dictionary<string, int>(), _loadingMsgId);
//msg.Content.Add("Mode", 0);
//Messenger.Default.Send<NotificationMessage<IDictionary<string, int>>> (msg, _loadingMsgId);
Detail = mainNav;
this.Icon = "slideout.png";
_master.PageSelectionChanged = (measurementTypeDefId) => {
IDictionary<string, int> msgSelectionChanged = new Dictionary<string, int>();
msgSelectionChanged.Add("DefinitionId", measurementTypeDefId);
msgSelectionChanged.Add("Mode", 0);
var page = App.NavigationService.MasterNavigateTo (MeasurementPage.PageName, msgSelectionChanged);
Detail = new NavigationPage(page);
Detail.Title = page.Title;
IsPresented = false;
};
}
示例13: GetValidator
/// <summary>
/// Получить экземпляр типа <see cref="SqlDateTimeValidator"/>.
/// </summary>
/// <returns>Экземпляр валидатора.</returns>
public override IValidator GetValidator(ILifetimeScope scope)
{
var validator = scope.Resolve<SqlDateTimeValidator>();
validator.Message = ErrorMessage;
return validator;
}
示例14: MessageFeedbackProcessor
public MessageFeedbackProcessor(
ILifetimeScope scope,
IDeviceLogic deviceLogic)
{
IConfigurationProvider configProvider;
if (scope == null)
{
throw new ArgumentNullException("scope");
}
if (deviceLogic == null)
{
throw new ArgumentNullException("deviceLogic");
}
configProvider = scope.Resolve<IConfigurationProvider>();
_iotHubConnectionString =
configProvider.GetConfigurationSettingValue(
"iotHub.ConnectionString");
if (string.IsNullOrEmpty(_iotHubConnectionString))
{
throw new InvalidOperationException(
"Cannot find configuration setting: \"iotHub.ConnectionString\".");
}
_deviceLogic = deviceLogic;
}
示例15: Application_Startup
private void Application_Startup(object sender, StartupEventArgs e)
{
_scope = Container.BeginLifetimeScope();
_scope.Resolve<ApplicationWindow>().Show();
Messenger.Default.Send(new ApplicationMessage(NotificationKind.Initialized));
}