當前位置: 首頁>>代碼示例>>C#>>正文


C# Unity.UnityContainer類代碼示例

本文整理匯總了C#中Microsoft.Practices.Unity.UnityContainer的典型用法代碼示例。如果您正苦於以下問題:C# UnityContainer類的具體用法?C# UnityContainer怎麽用?C# UnityContainer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UnityContainer類屬於Microsoft.Practices.Unity命名空間,在下文中一共展示了UnityContainer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            //Unity
            var container = new UnityContainer();
            container.RegisterType<IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());
            container.RegisterType<IGenericRepository<Farmacia>, GenericRepository<Farmacia>>(new HierarchicalLifetimeManager());
            config.DependencyResolver = new UnityResolver(container);

            //Formatters
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            //GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            //config.Formatters.Insert(0, new System.Net.Http.Formatting.JsonMediaTypeFormatter());

            // Web API routes
            config.MapHttpAttributeRoutes();
            //config.EnableCors();
            var cors = new EnableCorsAttribute("http://localhost:28285", "*", "*");
            config.EnableCors(cors);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
開發者ID:RubenGomes10,項目名稱:Farma,代碼行數:30,代碼來源:WebApiConfig.cs

示例2: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     IUnityContainer container = new UnityContainer();
     UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
     section.Configure(container);
     if (Request["installation"] != null)
     {
         int installationid = Int32.Parse(Request["installation"]);
         userid = Int32.Parse(Request["userid"]);
         user = Request["user"];
         sservice = container.Resolve<IStatisticService>();
         IInstallationBL iinstall = container.Resolve<IInstallationBL>();
         imodel = iinstall.getInstallation(installationid);
         Dictionary<InstallationModel, List<InstallationState>> statelist = sservice.getInstallationState(imodel.customerid);
         StringBuilder str = new StringBuilder();
         str.Append("<table border = '1'><tr><th>Description</th><th>Messwert</th><th>Einheit</th></tr>");
         foreach (var values in statelist)
         {
             if(values.Key.installationid.Equals(installationid))
             {
                 foreach (var item in values.Value)
                 {
                      str.Append("<tr><td>" + item.description + "</td><td>" + item.lastValue + "</td><td>" + item.unit + "</td></tr>");
                 }
                 break;
             }
         }
         str.Append("</table>");
         anlagenzustand.InnerHtml = str.ToString();
     }
 }
開發者ID:daniel9992000,項目名稱:bif5-sks-csharp,代碼行數:31,代碼來源:InstallationDetail.aspx.cs

示例3: RegisterComponents

        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>();

            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
            // repositories injection
            container.RegisterType<IRepository<Item, int>, ItemRepository>();
            container.RegisterType<IRepository<Category, int>, CategoryRepository>();
            container.RegisterType<IRepository<Reservation, int>, ReservationRepository>();
            container.RegisterType<IRepository<Image, int>, ImageRepository>();

            // authentication injection
            container.RegisterType<DbContext, ReservationContext>(new HierarchicalLifetimeManager());
            container.RegisterType<UserManager<User>, ApplicationUserManager>();
            container.RegisterType<ReservationContext>(new HierarchicalLifetimeManager());
            container.RegisterType<ApplicationUserManager>();

            container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
            container.RegisterType<ITextEncoder, Base64TextEncoder>();
            container.RegisterType<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
            container.RegisterType<IDataProtector>(new InjectionFactory(o => new DpapiDataProtectionProvider().Create("ASP.NET Identity")));

            container.RegisterType<IUserStore<User>, UserStore<User>>(new InjectionConstructor(typeof(ReservationContext)));
            container.RegisterType<IAuthenticationManager>(new InjectionFactory(o => HttpContext.Current.GetOwinContext().Authentication));
            container.RegisterType<IOwinContext>(new InjectionFactory(o => HttpContext.Current.GetOwinContext()));
        }
開發者ID:mikolajtr,項目名稱:reservations,代碼行數:31,代碼來源:UnityConfig.cs

示例4: LoginUser

        public static string LoginUser(string username, string password, string response)
        {
            string result = string.Empty;

            try
            {
                if (!IsRobot(response))
                {
                    IUnityContainer container = new UnityContainer();
                    container.RegisterType<AccountMgr>();
                    container.RegisterType<IAccountDacMgr, AccountDacMgr>();

                    AccountMgr accountMgr = container.Resolve<AccountMgr>();

                    accountMgr.UserName = username;
                    accountMgr.Password = password;

                    if (accountMgr.Login())
                    {
                        FormsAuthentication.SetAuthCookie(accountMgr.UserName, false);

                        result = "OK";
                    }
                }
            }
            catch
            {
                throw;
            }

            return result;
        }
開發者ID:wjkong,項目名稱:ApiExpert,代碼行數:32,代碼來源:Login.aspx.cs

示例5: BuildUnityContainer

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            // Register repository.
            container.RegisterType<IMyBigBroRepository, MyBigBroRepository>(
                new InjectionConstructor(new MyBigBroContext(GetConnectionString())));

            // Register services.
            container.RegisterType<ILocation, Location>();
            container.RegisterType<IStorageServiceAgent, AzureStorageServiceAgent>();
            container.RegisterType<ILocation, Location>();
            container.RegisterType<IWebCamControl, WebCamControl>();
            container.RegisterType<IGeoMarkerService, GeoMarkerService>();
            container.RegisterType<IAccountService, AccountService>();
            container.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>();

            // Register Web API controllers.
            //container.RegisterType<LoginController>();
            container.RegisterType<GeoMarkersController>();
            container.RegisterType<CapturedImagesGeoMarkerController>();
            container.RegisterType<WebCamsController>();

            // Return the populated container.
            return container;
        }
開發者ID:bernardoleary,項目名稱:MyBigBro,代碼行數:26,代碼來源:Bootstrapper.cs

示例6: TryResolveShouldReturnNullIfElementNotExist

        public void TryResolveShouldReturnNullIfElementNotExist()
        {
            var container = new UnityContainer();

            object dependantA = container.TryResolve<IDependantA>();
            Assert.IsNull(dependantA);
        }
開發者ID:ValdimarThor,項目名稱:Prism,代碼行數:7,代碼來源:UnityContainerExtensionFixture.cs

示例7: BuildUnityContainer

 private static IUnityContainer BuildUnityContainer()
 {
     var container = new UnityContainer();
     container.RegisterType<IHomeService, HomeService>();
     MvcUnityContainer.Container = container;
     return container;
 }
開發者ID:cbsistem,項目名稱:Kitto-1,代碼行數:7,代碼來源:Bootstrapper.cs

示例8: AsyncMain

    static async Task AsyncMain()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Unity");

        UnityContainer container = new UnityContainer();
        container.RegisterInstance(new MyService());
        busConfiguration.UseContainer<UnityBuilder>(c => c.UseExistingContainer(container));
        #endregion
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);
        try
        {
            IBusSession busSession = endpoint.CreateBusSession();
            await busSession.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
開發者ID:cdnico,項目名稱:docs.particular.net,代碼行數:28,代碼來源:Program.cs

示例9: BuildUnityContainer

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();

            return container;
        }
開發者ID:jesusmoreno85,項目名稱:LoginTestApp,代碼行數:7,代碼來源:Bootstrapper.cs

示例10: Register

        public static void Register(HttpConfiguration config)
        {
            
            // Web API configuration and services
            //
            var container = new UnityContainer();

            //Service registration
            container.RegisterType<ITestService, TestService>(new HierarchicalLifetimeManager());

            //Data repository registration
            container.RegisterType<ITestRepo, TestRepo>(new HierarchicalLifetimeManager());



            config.DependencyResolver = new UnityDiResolver(container);


            // Web API routes - attribute routing
            //
            config.MapHttpAttributeRoutes();

            // Web API routes - conventional routing
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
開發者ID:bob1457,項目名稱:WBooking,代碼行數:29,代碼來源:WebApiConfig.cs

示例11: Register

        public static void Register(HttpConfiguration config)
        {
            // Dependency resolver for dependency injection
            UnityContainer container = new UnityContainer();
            container.RegisterType<IResearchRepository, ResearchRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IProjectsRepository, ProjectsRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IReferencesRepository, ReferencesRepository>(new HierarchicalLifetimeManager());
            config.DependencyResolver = new UnityResolver(container);

            config.MapHttpAttributeRoutes();

            // API routes
            config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional });

            //OData Models
            ODataModelBuilder odataBuilder = new ODataConventionModelBuilder();
            odataBuilder.Namespace = "SpResearchTracker.Models";
            odataBuilder.EntitySet<Project>("Projects");
            odataBuilder.EntitySet<Reference>("References");

            // OData routes
            config.Routes.MapODataRoute(
              routeName: "odata",
              routePrefix: "odata",
              model: odataBuilder.GetEdmModel(),
              batchHandler: new BreezeODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
開發者ID:ruperthulme,項目名稱:Research-Project-Code-Sample,代碼行數:30,代碼來源:WebApiConfig.cs

示例12: Register

 public void Register(UnityContainer container)
 {
     container
         .ConfigureAutoRegistration()
         .Include(x => x.Assembly == Assembly.GetExecutingAssembly(), Then.Register().AsAllInterfacesOfType().UsingPerCallMode())
         .ApplyAutoRegistration();
 }
開發者ID:swmal,項目名稱:DiIocDemo,代碼行數:7,代碼來源:RegisterAllModule.cs

示例13: Application_Start

        /// <summary>
        /// Application Entry Point
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //*************************************************************
            AppDomain.CurrentDomain.UnhandledException +=
                delegate(object sender, UnhandledExceptionEventArgs e)
                {
                    Logging.LogManagerProvider.Instance.WriteError(e.ExceptionObject as Exception);
                };

            //logging initialization
            Logging.LogManagerProvider.Initialize("LoggingSection");

            //Repository and controller initialization
            UnityContainer container = new UnityContainer();
            RepositoryProvider.Register(container, "RepositoryProvider");
            GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
            //*************************************************************
        }
開發者ID:spbuksh,項目名稱:CuratedGalleries,代碼行數:28,代碼來源:Global.asax.cs

示例14: RegisterUnityContainer

        private UnityContainer RegisterUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();

            return container;
        }
開發者ID:fanshu,項目名稱:CoursewareDI,代碼行數:7,代碼來源:Global.asax.cs

示例15: Resolve

        public static void Resolve(UnityContainer container)
        {
            container.RegisterType<DataBaseContext, DataBaseContext>(new HierarchicalLifetimeManager());
            container.RegisterType<IUsuarioService, UsuarioService>(new HierarchicalLifetimeManager());
            container.RegisterType<IUsuarioRepository, UsuarioRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IPermissaoRepository, PermissaoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IGrupoPermissaoRepository, GrupoPermissaoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IAutenticacao, AutenticacaoService>(new HierarchicalLifetimeManager());

            container.RegisterType<IPessoaService, PessoaService>(new HierarchicalLifetimeManager());
            container.RegisterType<IPessoaRepository, PessoaRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IPapelRepository, PapelRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IPessoaFisicaRepository, PessoaFisicaRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IPessoaJuridicaRepository, PessoaJuridicaRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IMeioComunicacaoRepository, MeioComunicacaoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IEnderecoRepository, EnderecoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IEstadoCivilRepository, EstadoCivilRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IEstadoRepository, EstadoRepository>(new HierarchicalLifetimeManager());

            container.RegisterType<IProdutoService, ProdutoService>(new HierarchicalLifetimeManager());
            container.RegisterType<IProdutoRepository, ProdutoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IUnidadeRepository, UnidadeRepository>(new HierarchicalLifetimeManager());

            container.RegisterType<ICondicaoPagamentoService, CondicaoPagamentoService>(new HierarchicalLifetimeManager());
            container.RegisterType<IFormaPagamentoService, FormaPagamentoService>(new HierarchicalLifetimeManager());
            container.RegisterType<ICondicaoPagamentoRepository, CondicaoPagamentoRepository>(new HierarchicalLifetimeManager());
            container.RegisterType<IFormaPagamentoRepository, FormaPagamentoRepository>(new HierarchicalLifetimeManager());

            //container.RegisterType<User, User>(new HierarchicalLifetimeManager());
        }
開發者ID:felipeffs6,項目名稱:RepositorioGitProjetoArtCouro,代碼行數:30,代碼來源:DependencyResolver.cs


注:本文中的Microsoft.Practices.Unity.UnityContainer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。