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


C# SimpleInjector.Container類代碼示例

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


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

示例1: RegistrationContainers

        public static void RegistrationContainers()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            container.Register<IUnitOfWork, UnitOfWork>(Lifestyle.Scoped);
            container.Register<IAddressManager, AddressManager>();
            container.Register<ICarManager, CarManager>();
            container.Register<ICoordinatesManager, CoordinatesManager>();
            container.Register<IDistrictManager, DistrictManager>();
            container.Register<ILocationManager, LocationManager>();
            container.Register<IPersonManager, PersonManager>();
            container.Register<ITarifManager, TarifManager>();
            container.Register<IUserManager, UserManager>();
            container.Register<IDriverLocationHelper, DriverLocationHelper>();
            container.Register<IWorkerStatusManager, WorkerStatusManager>();
            container.Register<ISupportManager, SupportManager>();
            container.Register<IOrderManagerEx, OrderManagerEx>();
            container.Register<IDriverExManager, DriverExManager>();
            container.Register<ITariffExManager, TariffExManager>();
            container.Register<IFeedbackManager, FeedbackManager>();
            container.Register<INewsManager, NewsManager>();
            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
開發者ID:CH033dotNET,項目名稱:Taxi,代碼行數:25,代碼來源:SimpleInjectorDependency.cs

示例2: ConfigureSimpleInjector

        //Register Container for classes that use dependecy Injection
        private Container ConfigureSimpleInjector(IAppBuilder app)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            container.Register<IUserStore<User, int>, UserStore>(Lifestyle.Scoped);

            container.Register<IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);

            container.Register<IUnitOfWork, UnitOfWork>();

            container.Register<IAuthRepository, AuthRepository>();
            container.Register<ICommentRepository, CommentRepository>();
            container.Register<IUserRepository, UserRepository>();
            container.Register<ICompanyProfileRepository, CompanyProfileRepository>();
            container.Register<IInsuranceAgentProfileRepository, InsuranceAgentProfileRepository>();
            container.Register<ILeadProductRepository, LeadProductRepository>();
            container.Register<ILeadTransactionRepository, LeadTransactionRepository>();
            container.Register<IReviewPostRepository, ReviewPostRepository>();

            app.Use(async (context, next) => {
                    using (container.BeginExecutionContextScope())
                    {
                        await next();
                    }
                });

            container.Verify();

            return container;
        }
開發者ID:jeffward01,項目名稱:ReviewApplicaiton,代碼行數:33,代碼來源:Startup.cs

示例3: RunApp

        private static void RunApp(Container container)
        {
            try
            {
                XamlGeneratedNamespace.GeneratedApplication app = new XamlGeneratedNamespace.GeneratedApplication();
                ((WpfApplication)container.GetInstance<IApplication>()).Initialize();
                app.InitializeComponent();
                app.Startup += (sender, args) =>
                {
                    ThemeManager.AddAccent("WhiteAccent",
                        new Uri("pack://application:,,,/DSImager.Application;component/Themes/WhiteAccent.xaml"));
                    ThemeManager.AddAppTheme("WhiteTheme",
                        new Uri("pack://application:,,,/DSImager.Application;component/Themes/WhiteTheme.xaml"));
                };
                var mainWin = container.GetInstance<MainWindow>();
                container.GetInstance<ILogService>().Trace(LogEventCategory.Informational, "App is starting");
                app.Run(mainWin);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
開發者ID:Jusas,項目名稱:DSImager,代碼行數:25,代碼來源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            // 1. Create a new Simple Injector container
            var container = new Container();

            // 2. Configure the container (register)
            container.Register<IMongoProvider, MongoProvider>(Lifestyle.Singleton);
            container.Register<IInputProvider, MongoInputProvider>();
            container.Register<IOutputProvider, MongoOutputProvider>();
            container.Register<IParseProvider,ConsoleParseProvider>();
            container.Register<IMathProvider, DefaultMathProviderProvider>();

            // 3. Optionally verify the container's configuration.
            container.Verify();

            /*
            var calc = new Calculator(
                new MongoInputProvider(new MongoProvider("localhost:\\mongo")), //<===
                new MongoOutputProvider(new MongoProvider("localhost:\\mongo")),//<=== 
                new ConsoleParseProvider(),
                new DefaultMathProviderProvider()
                );

            */
            var calc = container.GetInstance<Calculator>();
            calc.MainLoop();

            Console.ReadLine();
        }
開發者ID:NahumLitvin,項目名稱:Ioc.QuickStart,代碼行數:29,代碼來源:Program.cs

示例5: Initialize

        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();

            InitializeContainer(container);

            try
            {
                container.Verify();
            }
            catch (Exception exception)
            {
                Trace.TraceError("{0}", exception);
                throw;
            }

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.Services.Replace(typeof (IFilterProvider), new SimpleInjectorWebApiFilterProvider(container));

            try
            {
                new TraceListenersInitializer(container.GetInstance<IPortalSettings>(), container.GetInstance<IEmailSenderService>()).Initialize();
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to initialize trace listeners: {0}", e);
                throw;
            }
        }
開發者ID:GusLab,項目名稱:video-portal,代碼行數:30,代碼來源:SimpleInjectorInitializer.cs

示例6: Setup

 protected virtual void Setup()
 {
     _container = new Container();
     _container.Options.AllowOverridingRegistrations = true;
     foreach (var registrar in GetRegistrars().OrderBy(x => x.Order))
         registrar.Register(_container);
 }
開發者ID:pauldotknopf,項目名稱:skimur,代碼行數:7,代碼來源:TestBase.cs

示例7: Register

        public static void Register(Container container)
        {
            container.Register(typeof (IQueryHandler<,>), new[] {typeof (IQueryHandler<,>).Assembly});
            container.Register(typeof (ICommandHandler<,>), new[] {typeof (ICommandHandler<,>).Assembly});

            container.RegisterCollection(typeof (IHyperMediaState), typeof (IHyperMediaState).Assembly);
            container.Register<IBoardState, BoardState>();
            container.Register<IBoardTaskState, BoardTaskState>();
            container.Register<IBoardColumnState, BoardColumnState>();

            container.Register<ISlugService, SlugService>();

            container.Register<ICommandDispatcher, CommandDispatcher>();
            container.Register<IQueryDispatcher, QueryDispatcher>();
            container.Register<ILinkFactory, LinkFactory>();
            container.Register<IHyperMediaFactory, HyperMediaFactory>();
            container.Register<IMappingService, MappingService>();

            container.RegisterWebApiRequest<IDataContext, DataContext>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.EnableHttpRequestMessageTracking(GlobalConfiguration.Configuration);
            container.RegisterSingleton<IRequestMessageProvider>(new RequestMessageProvider(container));

            container.Register<IValidator<Board>, BoardValidator>();
            container.Register<IValidator<BoardColumn>, BoardColumnValidator>();
            container.Register<IValidator<BoardTask>, BoardTaskValidator>();

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
開發者ID:linal,項目名稱:KanbanBoardApi,代碼行數:32,代碼來源:SimpleInjectorConfig.cs

示例8: InitializeContainer

        private static void InitializeContainer(Container container)
        {
            container.Register<ICardRepository, CardRepository>();

            // For instance:
            // container.Register<IUserRepository, SqlUserRepository>(Lifestyle.Scoped);
        }
開發者ID:danielrjames,項目名稱:BizCardBuilder,代碼行數:7,代碼來源:SimpleInjectorInitializer.cs

示例9: MessageChannel

 public MessageChannel(Container container, RabbitMQServer server, ICommandDiscovery commandDiscovery, IEventDiscovery eventDiscovery)
 {
     _container = container;
     _server = server;
     _commandDiscovery = commandDiscovery;
     _eventDiscovery = eventDiscovery;
 }
開發者ID:gpauls,項目名稱:MS,代碼行數:7,代碼來源:MessageChannel.cs

示例10: Configure

        public override void Configure(Container container)
        {
            container.Register<IConsole, SystemConsole>();
            container.Register<IThreadService, ThreadService>();

            ViewEngines.Add<RazorViewEngine>();
        }
開發者ID:Boggin,項目名稱:Consolas,代碼行數:7,代碼來源:Program.cs

示例11: Initialize

        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            // Chamada dos módulos do Simple Injector
            InitializeContainer(container);

            // Necessário para registrar o ambiente do Owin que é dependência do Identity
            // Feito fora da camada de IoC para não levar o System.Web para fora
            container.RegisterPerWebRequest(() =>
            {
                if (HttpContext.Current != null && HttpContext.Current.Items["owin.Environment"] == null && container.IsVerifying())
                {
                    return new OwinContext().Authentication;
                }
                return HttpContext.Current.GetOwinContext().Authentication;

            });

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
開發者ID:varcalsys,項目名稱:CONTABILIDADE_AERODRIGUES,代碼行數:26,代碼來源:SimpleInjectorInitializer.cs

示例12: Configuration

        public static Container Configuration(Container kernel)
        {
            kernel.Register<ICommercialRepository, CommercialRepository>(Lifestyle.Singleton);
            kernel.Verify();

            return kernel;
        }
開發者ID:igorquintaes,項目名稱:TibiaCommunity,代碼行數:7,代碼來源:IoCModule.cs

示例13: TypeRegistrationProvider

        /// <summary>
        /// Constructor.  Creates a new TypeRegistrationProvider instance.
        /// </summary>
        /// <param name="container">SimpleInjector Container instance</param>
        /// <param name="options">Registration options to use to auto-register types.</param>
        public TypeRegistrationProvider(Container container, IAutoRegistrationOptions options)
        {
            this.container = container;
            this.options = options;

            this.container.Options.AllowOverridingRegistrations = true;
        }
開發者ID:keithaknight,項目名稱:SimpleInjector.AutoRegistration,代碼行數:12,代碼來源:TypeRegistrationProvider.cs

示例14: Register

        public static void Register(Container container)
        {
            container.RegisterOpenGeneric(typeof(IRepository<>), typeof(Repository<>));

            // Single services
            container.Register<IContext, DefaultContext>();
            container.Register<ICommandPersister, DefaultCommandPersister>();
            container.Register<ICommandSerializer, NewtonsoftCommandSerializer>();
            //container.Register<ICommandSerializer, JilCommandSerializer>();

            AddInterfaceForEachDerivedType(container, typeof(TableBase), typeof(ITableBeforeSave<>));
            AddInterfaceForEachDerivedType(container, typeof(TableBase), typeof(ITableAfterSave<>));

            AddInterfaceForEachDerivedType(container, typeof(CommandBase), typeof(ICommandBeforeProcess<>));
            AddInterfaceForEachDerivedType(container, typeof(CommandBase), typeof(ICommandBeforeSave<>));
            AddInterfaceForEachDerivedType(container, typeof(CommandBase), typeof(ICommandAfterSave<>));

            // default persister
            container.RegisterOpenGeneric(typeof(ICommandSave<>), typeof(DefaultSaver<>));

            // override persisters
            container.Options.AllowOverridingRegistrations = true;

            //container.RegisterOpenGeneric(typeof(InsertCommandFor<>), typeof(SimpleCommandsDefaultSaver<>));
            //container.RegisterManyForOpenGeneric(typeof(ICommandSave<>), AppDomain.CurrentDomain.GetAssemblies());
            //container.RegisterManyForOpenGeneric(typeof(ICommandSave<>).MakeGenericType(typeof(InsertCommandFor<>)), AppDomain.CurrentDomain.GetAssemblies());
            /*
            ReplaceInterfaceForEachDerivedType(container, 
                typeof(SimpleCommand<>), 
                typeof(ICommandSave<>).MakeGenericType(typeof(InsertCommandFor<>))
                );*/

            //RegisterAllPersisters();

        }
開發者ID:aduggleby,項目名稱:dragon,代碼行數:35,代碼來源:DependencyConfig.cs

示例15: InitSiteContainer

        private static void InitSiteContainer(Container container)
        {
            container.Register<Fx.Domain.Account.IService.IAccountService, Fx.Domain.Account.UserAccountService>();
            container.Register<Fx.Domain.FxSite.IService.IChannelService, Fx.Domain.FxSite.ChannelService>();
            container.Register<Fx.Domain.FxSite.IService.ISite, Fx.Domain.FxSite.SiteService>();

            container.Register<Fx.Domain.FxSite.IService.IGoods, Fx.Domain.FxSite.GoodsService>();
            container.Register<Fx.Domain.FxSite.IService.ICar, Fx.Domain.FxSite.CarService>();
            container.Register<Fx.Domain.FxSite.IService.IHouse, Fx.Domain.FxSite.HouseService>();

            //FxGoods
            container.Register<Fx.Domain.FxGoods.IService.ITransferGoods, Fx.Domain.FxGoods.FxTransferGoodService>();
            container.Register<Fx.Domain.FxGoods.IService.IBuyGoods, Fx.Domain.FxGoods.FxBuyGoodsService>();

            //FxCar
            container.Register<Fx.Domain.FxCar.IService.ITransferCar, Fx.Domain.FxCar.FxTransferCarService>();
            container.Register<Fx.Domain.FxCar.IService.IBuyCar, Fx.Domain.FxCar.FxBuyCarService>();

            //FxHouse
            container.Register<Fx.Domain.FxHouse.IService.ITransferHouse, Fx.Domain.FxHouse.FxTransferHouseService>();
            container.Register<Fx.Domain.FxHouse.IService.IBuyHouse, Fx.Domain.FxHouse.FxBuyHouseService>();

            //�������
            container.RegisterSingle<Fx.Infrastructure.Caching.ICacheManager, Fx.Infrastructure.Caching.CacheManager>();
        }
開發者ID:Aaronguo,項目名稱:FxCacheService,代碼行數:25,代碼來源:SimpleInjectorInitializer.cs


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