public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes) { container.RegisterType <TraceSource>( new ContainerControlledLifetimeManager(), new InjectionFactory(c => { var name = ConfigurationManager .AppSettings["radical/windows/presentation/diagnostics/applicationTraceSourceName"] .Return(s => s, "default"); return(new TraceSource(name)); })); container.RegisterType <Application>( new ContainerControlledLifetimeManager(), new InjectionFactory(c => { return(Application.Current); })); container.RegisterType <Dispatcher>( new ContainerControlledLifetimeManager(), new InjectionFactory(c => { return(Application.Current.Dispatcher); })); container.RegisterType <IMessageBroker, MessageBroker>(new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); container.RegisterType <IDispatcher, WpfDispatcher>(new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); }
public void Install( IUnityContainer container, BootstrapConventions conventions, IEnumerable<Type> allTypes ) { allTypes .Where( t => conventions.IsService( t ) && !conventions.IsExcluded( t ) ) .Select( type => { return new { Contracts = conventions.SelectServiceContracts( type ), TypeTo = type }; } ) .ForEach( r => { /* * questa è una magagna perchè Unity non ci consente la registrazione dei forwarder * ed è un macello perché anche se riuscissimo ad iniettare una policy che "conosce" * i forwarder ci scontriamo con il fatto che le build-key, in apparenza, infilate nella * ContainerRegistration vengono risolte immediatamente all'avvio e non on-demend, ergo * non abbiamo come in Castle il concetto di "attesa" per le dipendenze. */ container.RegisterType( r.TypeTo, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) ); foreach ( var contract in r.Contracts ) { container.RegisterType( contract, new InjectionFactory( c => { return c.Resolve( r.TypeTo ); } ) ); } } ); }
public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes) { allTypes .Where(t => conventions.IsService(t) && !conventions.IsExcluded(t)) .Select(type => { return(new { Contracts = conventions.SelectServiceContracts(type), TypeTo = type }); }) .ForEach(r => { /* * questa è una magagna perchè Unity non ci consente la registrazione dei forwarder * ed è un macello perché anche se riuscissimo ad iniettare una policy che "conosce" * i forwarder ci scontriamo con il fatto che le build-key, in apparenza, infilate nella * ContainerRegistration vengono risolte immediatamente all'avvio e non on-demend, ergo * non abbiamo come in Castle il concetto di "attesa" per le dipendenze. */ container.RegisterType(r.TypeTo, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); foreach (var contract in r.Contracts) { container.RegisterType(contract, new InjectionFactory(c => { return(c.Resolve(r.TypeTo)); })); } }); }
public void Install(BootstrapConventions conventions, IServiceCollection services, IEnumerable <Type> assemblyScanningResults) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo .Console().CreateLogger(); services.AddLogging(e => e.AddSerilog()); }
public void Install(BootstrapConventions conventions, IServiceCollection services, IEnumerable <Type> assemblyScanningResults) { var endpoint = new NserviceBusEndpoint($"sniper-{Guid.NewGuid()}", services); services.AddSingleton(serviceProvider => { return(new Lazy <NserviceBusEndpoint>(() => { endpoint.Start(serviceProvider); return endpoint; })); }); }
public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies ) { assemblies.SelectMany( a => a.GetTypes() ) .Where( t => conventions.IsMessageHandler( t ) && !conventions.IsExcluded( t ) ) .Select( t => new { Contracts = conventions.SelectMessageHandlerContracts( t ), Implementation = t } ) .ForEach( r => { builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance(); } ); }
public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies) { assemblies.SelectMany(a => a.GetTypes()) .Where(t => conventions.IsMessageHandler(t) && !conventions.IsExcluded(t)) .Select(t => new { Contracts = conventions.SelectMessageHandlerContracts(t), Implementation = t }) .ForEach(r => { builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance(); }); }
public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies ) { builder.Register( c => { var name = ConfigurationManager .AppSettings[ "radical/windows/presentation/diagnostics/applicationTraceSourceName" ] .Return( s => s, "default" ); return new TraceSource( name ); } ) .As<TraceSource>().SingleInstance(); builder.Register( c => Application.Current ).As<Application>().SingleInstance(); builder.Register( c => Application.Current.Dispatcher ).As<Dispatcher>().SingleInstance(); builder.RegisterType<WpfDispatcher>().As<IDispatcher>().SingleInstance(); builder.RegisterType<MessageBroker>().As<IMessageBroker>().SingleInstance(); }
public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies) { builder.Register(c => { var name = ConfigurationManager .AppSettings["radical/windows/presentation/diagnostics/applicationTraceSourceName"] .Return(s => s, "default"); return(new TraceSource(name)); }) .As <TraceSource>().SingleInstance(); builder.Register(c => Application.Current).As <Application>().SingleInstance(); builder.Register(c => Application.Current.Dispatcher).As <Dispatcher>().SingleInstance(); builder.RegisterType <WpfDispatcher>().As <IDispatcher>().SingleInstance(); builder.RegisterType <MessageBroker>().As <IMessageBroker>().SingleInstance(); }
public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies ) { var types = assemblies.SelectMany( a => a.GetTypes() ).ToArray(); types.Where( t => conventions.IsViewModel( t ) && !conventions.IsExcluded( t ) ) .Select( t => new { Contracts = conventions.SelectViewModelContracts( t ), Implementation = t } ) .ForEach( r => { if ( conventions.IsShellViewModel( r.Contracts, r.Implementation ) ) { builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance(); } else { builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).InstancePerDependency(); } } ); types.Where( t => conventions.IsView( t ) && !conventions.IsExcluded( t ) ) .Select( t => new { Contracts = conventions.SelectViewContracts( t ), Implementation = t } ) .ForEach( r => { if ( conventions.IsShellView( r.Contracts, r.Implementation ) ) { builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance(); } else { builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).InstancePerDependency(); } } ); }
public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes) { allTypes .Where(t => conventions.IsViewModel(t) && !conventions.IsExcluded(t)) .Select(type => new { TypeFrom = conventions.SelectViewModelContracts(type).Single(), TypeTo = type }) .ForEach(r => { if (conventions.IsShellViewModel(new[] { r.TypeFrom }, r.TypeTo)) { container.RegisterType(r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); } else { container.RegisterType(r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector(container)); } }); allTypes .Where(t => conventions.IsView(t) && !conventions.IsExcluded(t)) .Select(type => new { TypeFrom = conventions.SelectViewContracts(type).Single(), TypeTo = type }) .ForEach(r => { if (conventions.IsShellView(new[] { r.TypeFrom }, r.TypeTo)) { container.RegisterType(r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); } else { container.RegisterType(r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector(container)); } }); }
public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies) { var types = assemblies.SelectMany(a => a.GetTypes()).ToArray(); types.Where(t => conventions.IsViewModel(t) && !conventions.IsExcluded(t)) .Select(t => new { Contracts = conventions.SelectViewModelContracts(t), Implementation = t }) .ForEach(r => { if (conventions.IsShellViewModel(r.Contracts, r.Implementation)) { builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance(); } else { builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).InstancePerDependency(); } }); types.Where(t => conventions.IsView(t) && !conventions.IsExcluded(t)) .Select(t => new { Contracts = conventions.SelectViewContracts(t), Implementation = t }) .ForEach(r => { if (conventions.IsShellView(r.Contracts, r.Implementation)) { builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance(); } else { builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).InstancePerDependency(); } }); }
public void Install( IUnityContainer container, BootstrapConventions conventions, IEnumerable<Type> allTypes ) { allTypes .Where( t => conventions.IsViewModel( t ) && !conventions.IsExcluded( t ) ) .Select( type => new { TypeFrom = conventions.SelectViewModelContracts( type ).Single(), TypeTo = type } ) .ForEach( r => { if ( conventions.IsShellViewModel( new[] { r.TypeFrom }, r.TypeTo ) ) { container.RegisterType( r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) ); } else { container.RegisterType( r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector( container ) ); } } ); allTypes .Where( t => conventions.IsView( t ) && !conventions.IsExcluded( t ) ) .Select( type => new { TypeFrom = conventions.SelectViewContracts( type ).Single(), TypeTo = type } ) .ForEach( r => { if ( conventions.IsShellView( new[] { r.TypeFrom }, r.TypeTo ) ) { container.RegisterType( r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) ); } else { container.RegisterType( r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector( container ) ); } } ); }
public void Install( IUnityContainer container, BootstrapConventions conventions, IEnumerable<Type> allTypes ) { container.RegisterType<IRegionManagerFactory, RegionManagerFactory>( new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) ); container.RegisterType<IRegionService, RegionService>( new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) ); container.RegisterType<IRegionManager, RegionManager>( new TransientLifetimeManager(), new CandidateConstructorSelector( container ) ); }
public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies ) { builder.RegisterType<RegionManagerFactory>().As<IRegionManagerFactory>().SingleInstance(); builder.RegisterType<RegionService>().As<IRegionService>().SingleInstance(); builder.RegisterType<RegionManager>().As<IRegionManager>().InstancePerDependency(); }
/// <summary> /// Initializes a new instance of the <see cref="ConventionsHanlder"/> class. /// </summary> /// <param name="broker">The broker.</param> /// <param name="releaser">The releaser.</param> /// <param name="bootstrapConventions">The Bootstrap Conventions</param> public ConventionsHanlder(IMessageBroker broker, IReleaseComponents releaser, BootstrapConventions bootstrapConventions) { this.broker = broker; this.releaser = releaser; this.bootstrapConventions = bootstrapConventions; this.DefaultResolveViewModelType = viewType => { var aName = new AssemblyName(viewType.Assembly.FullName); var vmTypeName = String.Format("{0}.{1}Model, {2}", viewType.Namespace, viewType.Name, aName.FullName); var vmType = Type.GetType(vmTypeName, false); return(vmType); }; this.ResolveViewModelType = viewType => { return(this.DefaultResolveViewModelType(viewType)); }; this.DefaultResolveViewType = viewModelType => { var aName = new AssemblyName(viewModelType.Assembly.FullName); var vTypeName = String.Format("{0}.{1}, {2}", viewModelType.Namespace, viewModelType.Name.Remove(viewModelType.Name.LastIndexOf('M')), aName.FullName); var vType = Type.GetType(vTypeName, true); return(vType); }; this.ResolveViewType = viewModelType => { return(this.DefaultResolveViewType(viewModelType)); }; this.DefaultViewReleaseHandler = (view, behavior) => { var autoDispose = view.GetType().IsAttributeDefined <ViewManualReleaseAttribute>() == false; if (autoDispose || behavior == ViewReleaseBehavior.Force) { var vm = this.GetViewDataContext(view, ViewDataContextSearchBehavior.LocalOnly); if (vm != null) { this.SetViewDataContext(view, null); if (this.ShouldUnsubscribeViewModelOnRelease(view)) { this.broker.Unsubscribe(vm); } this.releaser.Release(vm); } this.DetachViewBehaviors(view); this.releaser.Release(view); } }; this.ViewReleaseHandler = (view, behavior) => { this.DefaultViewReleaseHandler(view, behavior); }; Func <DependencyObject, Boolean> isSingletonView = view => { var implementation = view.GetType(); var contracts = this.bootstrapConventions.SelectViewContracts(implementation); var isShell = this.bootstrapConventions.IsShellView(contracts, implementation); return(isShell); }; this.DefaultShouldUnsubscribeViewModelOnRelease = view => !isSingletonView(view); this.ShouldUnsubscribeViewModelOnRelease = view => this.DefaultShouldUnsubscribeViewModelOnRelease(view); this.DefaultShouldReleaseView = view => !isSingletonView(view); this.ShouldReleaseView = view => this.DefaultShouldReleaseView(view); this.DefaultShouldUnregisterRegionManagerOfView = view => !isSingletonView(view); this.ShouldUnregisterRegionManagerOfView = view => this.DefaultShouldUnregisterRegionManagerOfView(view); this.DefaultFindHostingWindowOf = vm => { var view = this.GetViewOfViewModel(vm); var window = this.FindWindowOf(view); //.FindWindow(); return(window); }; this.FindHostingWindowOf = vm => { return(this.DefaultFindHostingWindowOf(vm)); }; this.DefaultFindWindowOf = dependencyObject => { var window = Window.GetWindow(dependencyObject); //.FindWindow(); return(window); }; this.FindWindowOf = dependencyObject => { return(this.DefaultFindWindowOf(dependencyObject)); }; this.DefaultViewHasDataContext = (view, behavior) => { return(this.GetViewDataContext(view, behavior) != null); }; this.ViewHasDataContext = (view, behavior) => { return(this.DefaultViewHasDataContext(view, behavior)); }; this.DefaultGetViewDataContext = (view, behavior) => { if (behavior == ViewDataContextSearchBehavior.Legacy) { if (view is FrameworkElement) { return((( FrameworkElement )view).DataContext); } #if !SILVERLIGHT else if (view is FrameworkContentElement) { return((( FrameworkContentElement )view).DataContext); } #endif } else { if (view is FrameworkElement) { var dc = view.ReadLocalValue(FrameworkElement.DataContextProperty); if (dc != DependencyProperty.UnsetValue) { return(dc); } } #if !SILVERLIGHT else if (view is FrameworkContentElement) { var dc = view.ReadLocalValue(FrameworkContentElement.DataContextProperty); if (dc != DependencyProperty.UnsetValue) { return(dc); } } #endif } return(null); }; this.GetViewDataContext = (view, behavior) => { return(this.DefaultGetViewDataContext(view, behavior)); }; this.DefaultSetViewDataContext = (view, dc) => { if (view is FrameworkElement) { (( FrameworkElement )view).DataContext = dc; } #if !SILVERLIGHT else if (view is FrameworkContentElement) { (( FrameworkContentElement )view).DataContext = dc; } #endif }; this.SetViewDataContext = (view, dc) => { this.DefaultSetViewDataContext(view, dc); }; this.DefaultTryHookClosedEventOfHostOf = (view, closedCallback) => { //dobbiamo anche cercare una IClosableView oltre che una Window var window = this.FindWindowOf(view); if (window != null) { #if SILVERLIGHT EventHandler <System.ComponentModel.ClosingEventArgs> closing = null; closing = (s, e) => { try { closedCallback(window); } finally { window.Closing -= closing; } }; window.Closing += closing; #else EventHandler closed = null; closed = (s, e) => { try { closedCallback(window); } finally { window.Closed -= closed; } }; window.Closed += closed; #endif } return(window); }; this.TryHookClosedEventOfHostOf = (view, closedCallback) => { return(this.DefaultTryHookClosedEventOfHostOf(view, closedCallback)); }; this.DefaultIsHostingView = fe => fe.GetType().Name.EndsWith("View"); this.IsHostingView = fe => this.DefaultIsHostingView(fe); this.DefaultAttachViewToViewModel = (view, viewModel) => { viewModel.As <IViewModel>(i => { i.View = view; }); }; this.AttachViewToViewModel = (view, viewModel) => { this.DefaultAttachViewToViewModel(view, viewModel); }; this.DefaultGetViewOfViewModel = viewModel => { if (viewModel is IViewModel) { return((( IViewModel )viewModel).View); } return(null); }; this.GetViewOfViewModel = viewModel => { return(this.DefaultGetViewOfViewModel(viewModel)); }; #if !SILVERLIGHT this.DefaultAttachViewBehaviors = view => { var bhv = Interaction.GetBehaviors(view); if (view is Window && bhv.OfType <WindowLifecycleNotificationsBehavior>().None()) { bhv.Add(new WindowLifecycleNotificationsBehavior(this.broker, this)); } else if (view is FrameworkElement && bhv.OfType <FrameworkElementLifecycleNotificationsBehavior>().None()) { bhv.Add(new FrameworkElementLifecycleNotificationsBehavior(this.broker, this)); } if (bhv.OfType <DependencyObjectCloseHandlerBehavior>().None()) { bhv.Add(new DependencyObjectCloseHandlerBehavior(this.broker, this)); } }; this.AttachViewBehaviors = view => { this.DefaultAttachViewBehaviors(view); }; #else this.AttachViewBehaviors = view => { var bhv = Interaction.GetBehaviors(view); //if( view is Page ) //{ // bhv.Add( new PageNavigationNotifcationsBehavior( this.broker ) ); //} bhv.Add(new FrameworkElementLifecycleNotificationsBehavior(this.broker, this)); bhv.Add(new DependencyObjectCloseHandlerBehavior(this.broker, this)); }; #endif #if !SILVERLIGHT this.DefaultDetachViewBehaviors = view => { var bhv = Interaction.GetBehaviors(view); if (view is Window) { bhv.OfType <WindowLifecycleNotificationsBehavior>().ToList().ForEach(x => bhv.Remove(x)); } else if (view is FrameworkElement) { bhv.OfType <FrameworkElementLifecycleNotificationsBehavior>().ToList().ForEach(x => bhv.Remove(x)); } bhv.OfType <DependencyObjectCloseHandlerBehavior>().ToList().ForEach(x => bhv.Remove(x)); }; this.DetachViewBehaviors = view => { this.DefaultDetachViewBehaviors(view); }; #else this.DetachViewBehaviors = view => { var bhv = Interaction.GetBehaviors(view); bhv.OfType <FrameworkElementLifecycleNotificationsBehavior>().ToList().ForEach(x => bhv.Remove(x)); bhv.OfType <DependencyObjectCloseHandlerBehavior>().ToList().ForEach(x => bhv.Remove(x)); }; #endif this.DefaultShouldNotifyViewModelLoaded = (view, dataContext) => { if (dataContext == null) { return(false); } var hasAttribute = dataContext.GetType().IsAttributeDefined <NotifyLoadedAttribute>(); var hasRegions = RegionService.CurrentService.HoldsRegionManager(view); return(hasAttribute || hasRegions); }; this.ShouldNotifyViewModelLoaded = (view, dataContext) => { return(this.DefaultShouldNotifyViewModelLoaded(view, dataContext)); }; this.DefaultShouldNotifyViewLoaded = view => { /* * we should decide if the attribute must be applied on the view or, as in this fix, * mainly for backward compatibility, can be applied also on the ViewModel and the * _View_Loaded message is still broadcasted. */ //var dataContext = this.GetViewDataContext( view ); //var hasAttributeOnViewModel = dataContext != null && dataContext.GetType().IsAttributeDefined<NotifyLoadedAttribute>(); var hasAttributeOnView = view.GetType().IsAttributeDefined <NotifyLoadedAttribute>(); var hasRegions = RegionService.CurrentService.HoldsRegionManager(view); return /* hasAttributeOnViewModel || */ (hasAttributeOnView || hasRegions); }; this.ShouldNotifyViewLoaded = view => { return(this.DefaultShouldNotifyViewLoaded(view)); }; }
public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes) { container.RegisterType <IRegionManagerFactory, RegionManagerFactory>(new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); container.RegisterType <IRegionService, RegionService>(new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container)); container.RegisterType <IRegionManager, RegionManager>(new TransientLifetimeManager(), new CandidateConstructorSelector(container)); }
public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies) { builder.RegisterType <RegionManagerFactory>().As <IRegionManagerFactory>().SingleInstance(); builder.RegisterType <RegionService>().As <IRegionService>().SingleInstance(); builder.RegisterType <RegionManager>().As <IRegionManager>().InstancePerDependency(); }
public SubscribeToMessageModule(Boot.BootstrapConventions conventions) { // TODO: Complete member initialization this.conventions = conventions; }
public InjectViewInRegionModule(BootstrapConventions conventions) { this.conventions = conventions; }