/// <summary>
        /// Initializes a new instance of the <see cref="DbContextItemTemplateWizard"/> class.
        /// </summary>
        /// <param name="model">The <see cref="ViewItemTemplateWizardViewModel">model</see> for the view.</param>
        /// <param name="projectInformation">The source <see cref="ProjectInformation">project information</see> used for browsing existing types.</param>
        /// <param name="shell">The <see cref="IVsUIShell">shell</see> used to provide user feedback.</param>
        /// <param name="dataExplorerConnectionManager">The <see cref="Lazy{T}">on-demand</see> <see cref="IVsDataConnectionDialogFactory"/> used to create new data connections.</param>
        /// <param name="dataConnectionDialogFactory">The <see cref="Lazy{T}">on-demand</see> <see cref="IVsDataExplorerConnectionManager">data explorer connection manager</see> used to add created data connections.</param>
        public DbContextItemTemplateWizard(
            DbContextItemTemplateWizardViewModel model,
            ProjectInformation projectInformation,
            IVsUIShell shell,
            Lazy<IVsDataConnectionDialogFactory> dataConnectionDialogFactory,
            Lazy<IVsDataExplorerConnectionManager> dataExplorerConnectionManager )
        {
            Arg.NotNull( shell, nameof( shell ) );
            Arg.NotNull( dataConnectionDialogFactory, nameof( dataConnectionDialogFactory ) );
            Arg.NotNull( dataExplorerConnectionManager, nameof( dataExplorerConnectionManager ) );

            InitializeComponent();
            Model = model;
            projectInfo = projectInformation;
            this.shell = shell;
            this.dataConnectionDialogFactory = dataConnectionDialogFactory;
            this.dataExplorerConnectionManager = dataExplorerConnectionManager;
        }
        /// <summary>
        /// Attempts to run the template wizard.
        /// </summary>
        /// <param name="shell">The <see cref="IVsUIShell">shell</see> associated with the wizard.</param>
        /// <returns>True if the wizard completed successfully; otherwise, false if the wizard was canceled.</returns>
        protected override bool TryRunWizard( IVsUIShell shell )
        {
            Arg.NotNull( shell, nameof( shell ) );

            var model = new DbContextItemTemplateWizardViewModel();
            var mapper = CreateMapper( model );
            var view = CreateView( model, shell );
            var statusBar = DesignTimeEnvironment.StatusBar;

            // the mapping relies on visual studio enumerating the available data sources,
            // which could take a while. we [seemingly] cannot run this in the background
            // so provide the user with some feedback to let them know we are doing work.
            statusBar.Text = SR.StatusInitializingDataSources;
            mapper.Map( Context.Replacements, model );
            statusBar.Clear();

            if ( !( view.ShowDialog( shell ) ?? false ) )
                return false;

            // map model back to replacements
            mapper.Map( model, Context.Replacements );
            return true;
        }
        private DbContextItemTemplateWizard CreateView( DbContextItemTemplateWizardViewModel model, IVsUIShell shell )
        {
            Contract.Requires( model != null );
            Contract.Requires( shell != null );
            Contract.Ensures( Contract.Result<DbContextItemTemplateWizard>() != null );

            var projectInfo = new ProjectInformation( Project );
            var dataConnectionDialogFactory = new Lazy<IVsDataConnectionDialogFactory>( Context.GetRequiredService<IVsDataConnectionDialogFactory> );
            var dataExplorerConnectionManager = new Lazy<IVsDataExplorerConnectionManager>( Context.GetRequiredService<IVsDataExplorerConnectionManager> );

            return new DbContextItemTemplateWizard( model, projectInfo, shell, dataConnectionDialogFactory, dataExplorerConnectionManager );
        }
        private DbContextReplacementsMapper CreateMapper( DbContextItemTemplateWizardViewModel model )
        {
            Contract.Requires( model != null );
            Contract.Ensures( Contract.Result<DbContextReplacementsMapper>() != null );

            var dataProviderManager = Context.GetRequiredService<IVsDataProviderManager>();
            var providerMapper = new Lazy<IDTAdoDotNetProviderMapper>( Context.GetRequiredService<IDTAdoDotNetProviderMapper> );
            var dataExplorerConnectionManager = Context.GetRequiredService<IVsDataExplorerConnectionManager>();
            Func<IVsDataConnectionManager> dataConnectionManagerFactory = Context.GetRequiredService<IVsDataConnectionManager>;
            IGlobalConnectionService globalConnectionService;

            // we honor the global connection service if available, but we don't need it
            Context.TryGetService( out globalConnectionService );

            return new DbContextReplacementsMapper( Project, Context, dataProviderManager, globalConnectionService, providerMapper, dataExplorerConnectionManager, dataConnectionManagerFactory );
        }
        private void UnwireInteractionRequests( DbContextItemTemplateWizardViewModel model )
        {
            if ( model == null )
                return;

            model.InteractionRequests["BrowseForModel"].Requested -= OnBrowseForModel;
            model.InteractionRequests["AddDataConnection"].Requested -= OnAddDataConnection;
        }