当前位置: 首页>>代码示例>>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;未经允许,请勿转载。