Ejemplo n.º 1
0
        /// <summary>
        /// Build 
        /// </summary>
        public static IUnityContainer BuildContainer()
        {
            var pinkoContainer = new UnityContainer();

            Trace.Listeners.Add(new TraceListenerDebug());

            //pinkoContainer.RegisterInstance<IPinkoConfiguration>(pinkoContainer.Resolve<PinkoConfiguration>());
            //pinkoContainer.RegisterInstance<IPinkoApplication>(pinkoContainer.Resolve<PinkoApplication>());
            ////pinkoContainer.RegisterInstance<ICloudConfigurationManager>(pinkoContainer.Resolve<AzureCloudConfigurationManager>());

            //pinkoContainer.RegisterInstance<IMessageHandlerManager>(pinkoContainer.Resolve<MessageHandlerManager>().Initialize()); // Handle messages

            //pinkoContainer.RegisterInstance<IBusMessageServer>(pinkoContainer.Resolve<AzureBusMessageServer>());
            ////pinkoContainer.RegisterInstance<IBusMessageServer>(pinkoContainer.Resolve<InMemoryBusMessageServer>().Initialize()); // when running offline
            //pinkoContainer.RegisterInstance<IBusMessageServer>(pinkoContainer.Resolve<MsMqBusMessageServer>().Initialize()); // when running offline

            if (ConfigurationManager.GetSection("unity") != null)
                pinkoContainer.LoadConfiguration();

            //            Microsoft.Practices.Unity.Configuration.UnityConfigurationSection

            //// Load unity config file
            //var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = "PinkoCommon.dll.config" };
            //var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            //var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
            //pinkoContainer.LoadConfiguration(unitySection);

            pinkoContainer.RegisterInstance<IRxMemoryBus<IBusMessageOutbound>>(pinkoContainer.Resolve<IPinkoApplication>().GetBus<IBusMessageOutbound>());

            return pinkoContainer;
        }
Ejemplo n.º 2
0
        public CascadingDropDownNameValue[] GetCities(string knownCategoryValues, string category)
        {
            var container = new UnityContainer();
            container.LoadConfiguration();

            StringDictionary ddlStateData = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            int state = Convert.ToInt32(ddlStateData["State"]);

            if (state > 0)
            {
                var cityBiz = container.Resolve<Business.ICity>();
                var cities = cityBiz.Query(c => c.State.Id == state, "State");

                List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

                foreach (var item in cities)
                {
                    values.Add(new CascadingDropDownNameValue(item.Name, item.Id.ToString()));
                }

                return values.ToArray();
            }

            return new CascadingDropDownNameValue[0];
        }
Ejemplo n.º 3
0
        public static IRepository GetRepository(string containerName)
        {
            //specify the file path
            string configName = String.Format(@"{0}/unity.config", System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath);
            var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configName };
            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");

            var container = new UnityContainer();
            if (String.IsNullOrEmpty(containerName))
                container.LoadConfiguration(unitySection);
            else
                container.LoadConfiguration(unitySection,containerName);

            return container.Resolve<IRepository>();
        }
Ejemplo n.º 4
0
        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();

            return container;
        }
Ejemplo n.º 5
0
        private UnityContainer RegisterUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();

            return container;
        }
        public static void Main(string[] args)
        {
            var diContainer = new UnityContainer();

            diContainer.LoadConfiguration();

            var source = diContainer.Resolve<ISnapshotSource>();

            while (true)
            {
                Console.WriteLine("Retrieving snapshots...");

                var snapshots = source.GetSnapshots();

                Parallel.ForEach(snapshots, snapshot =>
                {
                    var handler = diContainer.Resolve<ISnapshotSink>();

                    Console.WriteLine("Writing snapshot...");

                    handler.HandleSnapshot(snapshot);
                });

                Console.WriteLine("Sleeping...");

                Thread.Sleep(TimeSpan.FromSeconds(30));
            }
        }
Ejemplo n.º 7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (IUnityContainer container = new UnityContainer())
            {
                container.LoadConfiguration();

                container
                    .RegisterType(
                        typeof(IRepository<>),
                        typeof(ValidatingRepository<>),
                        "validating")
                    .RegisterType<IValidator<StockQuote>, RandomStockQuoteValidator>()
                    .RegisterType<ILogger, CompositeLogger>(
                        "composite",
                        new InjectionConstructor(
                            new ResolvedArrayParameter<ILogger>(
                                typeof(ILogger),
                                new ResolvedParameter<ILogger>("UI"))));

                StocksTickerPresenter presenter
                    = container.Resolve<StocksTickerPresenter>(
                        new ParameterOverride(
                            "repository",
                            new ResolvedParameter<IRepository<StockQuote>>("validating")).OnType<StocksTickerPresenter>(),
                        new PropertyOverride("Logger", new ResolvedParameter<ILogger>("composite")));

                Application.Run((Form)presenter.View);
            }
        }
        public UnityInstanceProvider(Type contractType, string containerName)
        {
            if (contractType == null)
            {
                throw new ArgumentNullException("contractType");

            }
            this._contractType = contractType;

            string key = containerName ?? "";
            if (Containers.ContainsKey(key))
            {
                this.Container = Containers[key];
                return;
            }
            IUnityContainer container = new UnityContainer();
            container.LoadConfiguration(containerName);
            lock (syncHelper)
            {
                if (!Containers.ContainsKey(key))
                {
                    Containers[key] = container;
                }
            }

            Container = container;
        }
Ejemplo n.º 9
0
        private static IUnityContainer BuildUnityContainer()
        {
            UnityContainer tempContainer = null;
            UnityContainer container;

            try
            {
                tempContainer = new UnityContainer();

                // Register your container mappings in the config file.
                // It will get loaded into the container with the following call:
                tempContainer.LoadConfiguration();

                container = tempContainer;
                tempContainer = null;
            }
            finally
            {
                if (tempContainer != null)
                {
                    tempContainer.Dispose();
                }
            }

            return container;
        }
Ejemplo n.º 10
0
 static void Main(string[] args)
 {
     IUnityContainer container = new UnityContainer();
     container.LoadConfiguration();
     var svc = container.Resolve<IMessageService>();
     svc.SendMessage("Michael", "Hello!");
 }
Ejemplo n.º 11
0
        static ApiSetup()
        {
            try
            {

                //Create
                Container = new UnityContainer();
                Locator = new UnityServiceLocator(Container);
                //Add entlib extensions
                Container.AddNewExtension<EnterpriseLibraryCoreExtension>();
#pragma warning disable 612,618
                Container.AddNewExtension<CachingBlockExtension>();
#pragma warning restore 612,618
                ServiceLocator.SetLocatorProvider(() => Locator);
                Container.LoadConfiguration("api");
                ApiDefaultConfig.DoDefaultRegistrations(Container);
                //NOTE: disabled for now
                //try
                //{
                //    ApiDefaultConfig.DoAutomaticConfiguration(Container);
                //    Initialization.Add(ApiSetupState.UnityAutoRegitrations, null);
                //}
                //catch (Exception e)
                //{
                //    Initialization.Add(ApiSetupState.UnityAutoRegitrations, new[] { e });
                //}
            }
            catch (Exception e)
            {
                Initialization.Add(ApiSetupState.UnityRegitrations, new[] { e });
                throw;
            }
            Initialization.Add(ApiSetupState.UnityRegitrations, null);
        }
		/// <summary>
		///     Initializes the unity container when the application starts up.
		/// </summary>
		/// <remarks>
		///		Do not edit this method. Perform any modifications in the
		///		<see cref="RegisterDependencies" /> method.
		/// </remarks>
		internal static void PostStart()
		{
			IUnityContainer container = new UnityContainer();
			HttpContext.Current.Application.SetContainer( container );
            container.LoadConfiguration();
			RegisterDependencies( container );
		}
Ejemplo n.º 13
0
 static CachingService()
 {
     var section = (UnityConfigurationSection) ConfigurationManager.GetSection("unity.caching");
     IUnityContainer container = new UnityContainer();
     container.LoadConfiguration(section);
     Store = container.Resolve<ICachingService>();
 }
Ejemplo n.º 14
0
        protected void Application_Start(object sender, EventArgs e)
        {
            IUnityContainer applicationContainer = new UnityContainer();
            applicationContainer.LoadConfiguration("application");

            ApplicationContainer = applicationContainer;
        }
Ejemplo n.º 15
0
 private void ResolveReferences()
 {
     using (var container = new UnityContainer())
     {
         container.LoadConfiguration();
         this.ResolveReferences(container);
     }
 }
Ejemplo n.º 16
0
 public void UploadMeasurement(string siteid, string unit, double value)
 {
     IUnityContainer unitycontainer = new UnityContainer();
     unitycontainer.LoadConfiguration("UnityContainer");
     SKS.Scada.BL.ISiteService siteserv = unitycontainer.Resolve<SKS.Scada.BL.ISiteService>();
     SKS.Scada.BL.IMeasurementService measureserv = unitycontainer.Resolve<SKS.Scada.BL.IMeasurementService>();
     siteserv.AddMeasurement(Convert.ToInt32(siteid), measureserv.CreateMeasurement(value, unit));
 }
Ejemplo n.º 17
0
        public void AddSite(Customer custom, string description, double longitude, double latitude)
        {
            IUnityContainer unitycontainer = new UnityContainer();
            unitycontainer.LoadConfiguration("UnityContainer");

            SKS.Scada.BL.ISiteService siteserv = unitycontainer.Resolve<SKS.Scada.BL.ISiteService>();
            siteserv.AddSite(custom, description, longitude, latitude);
        }
Ejemplo n.º 18
0
        public static IUnityContainer Build(ICommandLineOptions options, ProductInformation productInformation)
        {
            var container = new UnityContainer();

            var targetMapper = new TargetMapper();
            targetMapper.LoadFromConfig(options.TargetMapFile);

            container.RegisterInstance<ICommandLineOptions>(options);
            container.RegisterInstance<ITargetMapper>(targetMapper);

            // For debug purposes, the FileOutputApiPortService helps as it serializes the request to json and opens it with the
            // default json handler. To use this service, uncomment the the next line and comment the one after that.
            //container.RegisterType<IApiPortService, FileOutputApiPortService>(new ContainerControlledLifetimeManager());
            container.RegisterInstance<IApiPortService>(new ApiPortService(options.ServiceEndpoint, productInformation));

            container.RegisterType<IEnumerable<IgnoreAssemblyInfo>, FileIgnoreAssemblyInfoList>(new ContainerControlledLifetimeManager());
            container.RegisterType<IDependencyFinder, ReflectionMetadataDependencyFinder>(new ContainerControlledLifetimeManager());
            container.RegisterType<IDependencyFilter, DotNetFrameworkFilter>(new ContainerControlledLifetimeManager());
            container.RegisterType<IReportGenerator, ReportGenerator>(new ContainerControlledLifetimeManager());
            container.RegisterType<ApiPortService>(new ContainerControlledLifetimeManager());
            container.RegisterType<IFileSystem, WindowsFileSystem>(new ContainerControlledLifetimeManager());
            container.RegisterType<IFileWriter, ReportFileWriter>(new ContainerControlledLifetimeManager());
            container.RegisterType<IRequestAnalyzer, RequestAnalyzer>(new ContainerControlledLifetimeManager());
            container.RegisterType<IAnalysisEngine, AnalysisEngine>(new ContainerControlledLifetimeManager());
            container.RegisterType<ConsoleApiPort>(new ContainerControlledLifetimeManager());
            container.RegisterType<ICollection<IReportWriter>>(new ContainerControlledLifetimeManager(), new InjectionFactory(WriterCollection));
            container.RegisterType<IApiPortOptions>(new ContainerControlledLifetimeManager(), new InjectionFactory(GetOptions));
            container.RegisterType<DocIdSearchRepl>(new ContainerControlledLifetimeManager());
            container.RegisterType<ISearcher<string>, ApiPortServiceSearcher>(new ContainerControlledLifetimeManager());

            // Register the default output format name
            container.RegisterInstance(DefaultOutputFormatInstanceName, "Excel");

            if (Console.IsOutputRedirected)
            {
                container.RegisterInstance<IProgressReporter>(new TextWriterProgressReporter(Console.Out));
            }
            else
            {
                container.RegisterType<IProgressReporter, ConsoleProgressReporter>(new ContainerControlledLifetimeManager());
            }

#if FEATURE_DESKTOP_CONFIGURATION // Unity configuration is only available in its desktop package
            // Load any customizations via Unity
            var fileMap = new ExeConfigurationFileMap
            {
                ExeConfigFilename = Path.Combine(GetApplicationDirectory(), "unity.config")
            };

            var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");

            return unitySection == null ? container : container.LoadConfiguration(unitySection);
#else // FEATURE_DESKTOP_CONFIGURATION
            // TODO : Allow runtime configuration through some non-.config means?
            return container;
#endif // FEATURE_DESKTOP_CONFIGURATION
        }
Ejemplo n.º 19
0
        private static IUnityContainer BuildUnityContainer()
        {
            //LoadDependencyAssemblies();
            var container = new UnityContainer();

            container.LoadConfiguration();

            return container;
        }
Ejemplo n.º 20
0
 public Customer AddCustomer(string firstname, string email, string lastname, 
     string password, string username, Technician technician)
 {
     IUnityContainer unitycontainer = new UnityContainer();
     unitycontainer.LoadConfiguration("UnityContainer");
     SKS.Scada.BL.ICustomerService custserv = unitycontainer.Resolve<SKS.Scada.BL.ICustomerService>();
     return custserv.AddCustomer(firstname, email, lastname,
      password, username, technician);
 }
Ejemplo n.º 21
0
        private static void WithAppConfigurationFile()
        {
            IUnityContainer myContainer = new UnityContainer();
            myContainer.LoadConfiguration();
            A a1 = (A)myContainer.Resolve(typeof(A));

            A a2 = myContainer.Resolve<A>("A2");

            A a3 = (A)myContainer.Resolve<IA>();
        }
Ejemplo n.º 22
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            IUnityContainer container = new UnityContainer();
            container.LoadConfiguration();

            var mainWindowVM = container.Resolve<IMainWindowViewModel>();
            this.MainWindow = mainWindowVM.View as Window;
        }
        public static IUnityContainer Bootstrap()
        {
            IUnityContainer ContainerUnity = new UnityContainer();
            var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Constants.UnityConfiguration) };

            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
            ContainerUnity.LoadConfiguration(unitySection, Constants.UnityContainerName);
            return ContainerUnity;
        }
Ejemplo n.º 24
0
        public static void RegisterComponents()
        {
			var container = new UnityContainer();
            
            // register all your components with the container here
            // it is NOT necessary to register your controllers
            
            // e.g. container.RegisterType<ITestService, TestService>();
            container.LoadConfiguration();
            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
        }
Ejemplo n.º 25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _container = new UnityContainer();
            _container.LoadConfiguration();

            Session["activePageName"] = "Cadastro";

            if (!IsPostBack)
            {
                //BindDropDownLists();
            }
        }
Ejemplo n.º 26
0
        static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();
            Logger.SetLogWriter(new LogWriterFactory().Create());

            IConfigurationSource config = ConfigurationSourceFactory.Create();
            ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
            ExceptionManager exceptionManager = factory.CreateManager();
            ExceptionPolicy.SetExceptionManager(exceptionManager);
            return container;
        }
Ejemplo n.º 27
0
        public void Setup()
        {
            servico1RepositoryMock = new Mock<IServico1Repository>();

            var container = new UnityContainer();
            container.LoadConfiguration();
            servico1 = new Servico1(servico1RepositoryMock.Object);

            servico2 = container.Resolve<Servico2>();

            _servico3 = container.Resolve<Servico3>();
        }
Ejemplo n.º 28
0
        private static void Main(string[] args)
        {
            //Load configuration from app.config.
            IUnityContainer container = new UnityContainer();
            container.LoadConfiguration();

            //Resolve the class
            var myclass = container.Resolve<MyClass>();
            myclass.CallPrint();

            Console.Read();
        }
Ejemplo n.º 29
0
 IUnityContainer ConfigContainer() {
     IUnityContainer container = new UnityContainer();
     var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "unity.config");
     try {
         container.LoadConfiguration();
     }
     catch (Exception ex) {
         Console.WriteLine("Cannot config unity container from file {0}", filePath);
         Console.WriteLine(ex);
     }
     return container;
 }
        public void ChildContainerResolvesInParent()
        {
            var container = new UnityContainer();
            container.StandardConfiguration();
            container.LoadConfiguration();
            container.ConfigureRegistrars();

            var expected = container.ConfigureChildContainer("test");

            var candidate = container.Resolve<IUnityContainer>("test");

            Assert.AreSame(expected, candidate);
        }