/// <summary>
        /// Creates the DI container.
        /// </summary>
        /// <param name="context">The application context that controls the life time of the application.</param>
        /// <returns>The DI container.</returns>
        public static IContainer Load(ApplicationContext context)
        {
            IContainer result  = null;
            var        builder = new ContainerBuilder();

            {
                builder.Register(c => new XmlConfiguration(
                                     CommunicationConfigurationKeys.ToCollection()
                                     .Append(DiagnosticsConfigurationKeys.ToCollection())
                                     .ToList(),
                                     DatasetApplicationConstants.ConfigurationSectionApplicationSettings))
                .As <IConfiguration>();

                builder.Register(c => new FileSystem())
                .As <IFileSystem>();

                // Don't allow discovery on the dataset application because:
                // - The dataset application wouldn't know what to do with it anyway
                // - We don't want anybody talking to the application except for the
                //   application that started it.
                builder.RegisterModule(
                    new CommunicationModule(
                        new List <CommunicationSubject>
                {
                    CommunicationSubjects.Dataset,
                    CommunicationSubjects.Plugins,
                },
                        new[]
                {
                    ChannelType.NamedPipe,
                },
                        false));

                RegisterCommands(
                    builder,
                    () => CloseApplication(result),
                    file => LoadDatasetFile(result, file));
                RegisterNotifications(builder);

                builder.Register(c => context)
                .As <ApplicationContext>()
                .As <IDisposable>()
                .ExternallyOwned();

                RegisterLoggers(builder);
                RegisterProfiler(builder);
                RegisterDiagnostics(builder);
                RegisterScheduleStorage(builder);
                RegisterTimeline(builder);
                RegisterScheduleExecutors(builder);
                RegisterPartStorage(builder);
                RegisterDatasetLock(builder);
                RegisterAssemblyResolver(builder);
            }

            result = builder.Build();
            return(result);
        }
Example #2
0
        /// <summary>
        /// Override to add registrations to the container.
        /// </summary>
        /// <param name="builder">The builder through which components can be registered.</param>
        /// <remarks>
        /// Note that the ContainerBuilder parameter is not the same one
        /// that the module is being registered by (i.e. it can have its own defaults).
        /// </remarks>
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            // Register the global application objects
            {
                // Utilities
                builder.Register((c, p) => new ExceptionHandler(
                                     p.TypedAs <ExceptionProcessor[]>()))
                .As <ExceptionHandler>();

                builder.Register(c => new XmlConfiguration(
                                     CommunicationConfigurationKeys.ToCollection()
                                     .Append(DiagnosticsConfigurationKeys.ToCollection())
                                     .ToList(),
                                     ExplorerConstants.ConfigurationSectionApplicationSettings))
                .As <IConfiguration>();

                builder.Register(c => new NotificationReportingHub())
                .As <ICollectNotifications>()
                .SingleInstance();

                builder.Register(c => new ProgressReportingHub())
                .As <ICollectProgressReports>()
                .SingleInstance();

                builder.Register(c => new StepBasedProgressTracker())
                .OnActivated(
                    a =>
                {
                    var hub = a.Context.Resolve <ICollectProgressReports>();
                    hub.AddReporter(a.Instance);
                })
                .As <ITrackSteppingProgress>()
                .As <ITrackProgress>();

                RSAParameters rsaParameters = SrcOnlyExceptionHandlingUtilities.ReportingPublicKey();
                builder.RegisterModule(new FeedbackReportingModule(() => rsaParameters));

                RegisterLoggers(builder);
                RegisterProfiler(builder);
                RegisterDiagnostics(builder);
                RegisterAppDomainBuilder(builder);
                RegisterTimeline(builder);
            }
        }
        /// <summary>
        /// Creates the DI container.
        /// </summary>
        /// <returns>The DI container.</returns>
        public static IContainer Load()
        {
            IContainer result  = null;
            var        builder = new ContainerBuilder();

            {
                builder.Register(c => new XmlConfiguration(
                                     DiagnosticsConfigurationKeys.ToCollection(),
                                     RegressionApplicationConstants.ConfigurationSectionApplicationSettings))
                .As <IConfiguration>();

                RegisterLoggers(builder);
                RegisterDiagnostics(builder);
                RegisterReports(builder);
                RegisterTests(builder);
                RegisterLog(builder);
            }

            result = builder.Build();
            return(result);
        }
        /// <summary>
        /// Creates the DI container.
        /// </summary>
        /// <param name="context">The application context that can be used to terminate the application.</param>
        /// <param name="subjects">The collection of communication subjects for the current application.</param>
        /// <param name="allowChannelDiscovery">Indicates if automatic channel discovery should be turned on.</param>
        /// <returns>A new DI container.</returns>
        public static IContainer CreateContainer(
            ApplicationContext context,
            IEnumerable <CommunicationSubject> subjects,
            bool allowChannelDiscovery)
        {
            var builder = new ContainerBuilder();

            {
                builder.RegisterModule(
                    new CommunicationModule(
                        new[]
                {
                    ChannelTemplate.NamedPipe,
                    ChannelTemplate.TcpIP,
                },
                        allowChannelDiscovery));
                builder.RegisterModule(new UtilsModule());

                builder.Register(
                    c =>
                {
                    var ctx = c.Resolve <IComponentContext>();
                    Action <EndpointId, string> echoAction = (id, text) =>
                    {
                        var model = ctx.Resolve <ConnectionViewModel>();
                        model.AddNewMessage(id, text);
                    };
                    return(new TestCommands(
                               c.Resolve <DownloadDataFromRemoteEndpoints>(),
                               echoAction));
                })
                .SingleInstance();

                builder.Register(c => new TestNotifications())
                .SingleInstance();

                builder.Register(c => new CommunicationInitializer(
                                     c.Resolve <IComponentContext>(),
                                     subjects))
                .As <IInitializeCommunicationInstances>()
                .SingleInstance();

                // Register the elements from the current assembly
                builder.Register(c => new InteractiveWindow(
                                     context,
                                     c.Resolve <IHandleCommunication>()))
                .OnActivated(a =>
                {
                    a.Instance.ConnectionState = a.Context.Resolve <ConnectionViewModel>();
                })
                .As <InteractiveWindow>()
                .As <IInteractiveWindow>()
                .SingleInstance();

                builder.Register(c => new XmlConfiguration(
                                     CommunicationConfigurationKeys.ToCollection()
                                     .Append(DiagnosticsConfigurationKeys.ToCollection())
                                     .ToList(),
                                     TestConstants.ConfigurationSectionApplicationSettings))
                .As <IConfiguration>()
                .SingleInstance();

                builder.Register(c => new ApplicationCentral(
                                     c.Resolve <ICommunicationFacade>(),
                                     c.Resolve <ConnectionViewModel>()))
                .As <IFormTheApplicationCenter>()
                .SingleInstance();

                builder.Register(c => new ConnectionViewModel(
                                     c.Resolve <INotifyOfRemoteEndpointEvents>(),
                                     c.Resolve <InteractiveWindow>().Dispatcher))
                .OnActivated(
                    a =>
                {
                    foreach (var subject in subjects)
                    {
                        a.Instance.AddSubject(new CommunicationSubjectViewModel(subject));
                    }
                })
                .SingleInstance();

                builder.Register(c => new CommunicationPassThrough(
                                     c.Resolve <ISendCommandsToRemoteEndpoints>(),
                                     c.Resolve <IStoreUploads>(),
                                     c.Resolve <TestNotifications>()))
                .As <IHandleCommunication>();
            }

            return(builder.Build());
        }