public static void ProcessRegistrations(TinyIoC.TinyIoCContainer container) { var applicationRegistrationImplementations = AppDomain.CurrentDomain.GetAssemblies() .Where(a => a.GetReferencedAssemblies().Contains(typeof(ApplicationRegistar).Assembly.GetName()) || a == typeof(ApplicationRegistar).Assembly) .SelectMany(t => t.GetTypes()) .Where(t => t.Implements(typeof(IApplicationRegistration))) .ToList(); container.RegisterMultiple <IApplicationRegistration>(applicationRegistrationImplementations); var applicationRegistrations = container.ResolveAll <IApplicationRegistration>().ToList(); foreach (var typeRegistration in applicationRegistrations.SelectMany(ar => ar.TypeRegistrations)) { container.Register(typeRegistration.RegistrationType, typeRegistration.InstanceType); } foreach (var instanceRegistration in applicationRegistrations.SelectMany(ar => ar.InstanceRegistrations)) { container.Register(instanceRegistration.RegistrationType, instanceRegistration.Instance); } foreach (var collectionRegistration in applicationRegistrations.SelectMany(ar => ar.CollectionRegistration).GroupBy(cr => cr.RegistrationType)) { container.RegisterMultiple(collectionRegistration.Key, collectionRegistration.SelectMany(c => c.InstanceTypes)); } }
public KnockoutJQueryTmplPipeline_Tests() { var container = new TinyIoC.TinyIoCContainer(); container.Register(Mock.Of<IUrlGenerator>()); container.Register(new CassetteSettings()); pipeline = new KnockoutJQueryTmplPipeline(container); }
// Overriding this just to show how it works, not actually necessary as autoregister // takes care of it all. protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer existingContainer) { // We don't call base because we don't want autoregister // we just register our one known dependency as an application level singleton existingContainer.Register <IApplicationDependency, ApplicationDependencyClass>().AsSingleton(); existingContainer.Register <IRazorConfiguration, MyRazorConfiguration>().AsSingleton(); }
public JQueryTmplPipeline_Tests() { var container = new TinyIoC.TinyIoCContainer(); container.Register(Mock.Of <IUrlGenerator>()); container.Register(new CassetteSettings()); pipeline = new JQueryTmplPipeline(container); }
public JQueryTmplPipeline_Tests() { var container = new TinyIoC.TinyIoCContainer(); container.Register(Mock.Of<IUrlGenerator>()); container.Register(new CassetteSettings()); container.Register<IHtmlTemplateIdStrategy>(new HtmlTemplateIdBuilder()); pipeline = new JQueryTmplPipeline(container); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { var mefcontainer = CreateCompositionContainer(); container.Register(mefcontainer.GetExportedValues <IAnnounce>()); container.Register(mefcontainer.GetExportedValues <ISprocketInitializer>()); container.Register(new Bot(_serverUrl, _botName, _botPassword)); }
protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer existingContainer) { base.ConfigureRequestContainer(existingContainer); RequestContainerConfigured = true; existingContainer.Register <IFoo, Foo>().AsSingleton(); existingContainer.Register <IDependency, Dependency>().AsSingleton(); }
public JQueryTmplPipeline_Tests() { var container = new TinyIoC.TinyIoCContainer(); container.Register(Mock.Of <IUrlGenerator>()); container.Register(new CassetteSettings()); container.Register <IHtmlTemplateIdStrategy>(new HtmlTemplateIdBuilder()); pipeline = new JQueryTmplPipeline(container); }
public void GetServiceTest() { _ControllerDependencyResolver.GetService(typeof(IEnumerable)).Should().BeNull(); IEnumerable dummy = Mock.Of <IEnumerable>(); _IoCContainer.Register <IEnumerable>(dummy); _ControllerDependencyResolver.GetService(typeof(IEnumerable)).Should().Be(dummy); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { container.Register <IPersistentStore, PersistentStore>().AsSingleton(); var bus = StickABusInIt(container.Resolve <IPersistentStore>()); container.Register <ICommandSender, FakeBus>(bus); container.Register <IEventPublisher, FakeBus>(bus); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { container.Register(documentStore); container.Register(s3Configuration); container.Register <IS3Storage, RavenDBStorage>().AsSingleton(); var s3Responder = BuildResponder(); container.Register(s3Responder); }
public void InitContainer() { _NewContainer = new TinyIoC.TinyIoCContainer(); _NewContainer.Register <ISingleton, Singleton>().AsSingleton(); _NewContainer.Register <IParameterlessInstance, ParameterlessInstance>().AsMultiInstance(); _NewContainer.Register <ISingleParameterInstance, SingleParameterInstance>().AsMultiInstance(); _NewContainer.Register(typeof(IOpenGeneric <>), typeof(OpenGenericInstance <>)).AsMultiInstance(); _OriginalContainer = new TinyIoC.Original.TinyIoCContainer(); _OriginalContainer.Register <ISingleton, Singleton>().AsSingleton(); _OriginalContainer.Register <IParameterlessInstance, ParameterlessInstance>().AsMultiInstance(); _OriginalContainer.Register <ISingleParameterInstance, SingleParameterInstance>().AsMultiInstance(); _OriginalContainer.Register(typeof(IOpenGeneric <>), typeof(OpenGenericInstance <>)).AsMultiInstance(); }
public static void UpdateDependencies(bool useMocks) { // Change the injected dependencies as required if (useMocks) { // register mock services } else { // register actual services _container.Register <ISettingsService, SettingsService>(); } UseMockServices = useMocks; }
static ViewModelLocator() { _container = new TinyIoC.TinyIoCContainer(); // View models - by default, TinyIoC will register concrete classes as multi-instance _container.Register <HomePageViewModel>(); _container.Register <SettingsPageViewModel>(); // Services - by default, TinyIoC will regerter interface registrations as singletons. // Register services that do not depend on a mock service counterpart _container.Register <IDialogService, DialogService>(); _container.Register <INavigationService, NavigationService>(); // place any service registrations that have a mock counterpart in the UpdateDependencies method UpdateDependencies(false); }
protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container) { foreach (var mock in _mocks) { container.Register(mock.Key, mock.Value); } }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { base.ConfigureApplicationContainer(container); var mongoUrlStore = new MongoUrlStore("mongodb://localhost:27017/short_url"); container.Register <UrlStore>(mongoUrlStore); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { base.ConfigureApplicationContainer(container); string mongoConnectionString = ConfigurationManager.AppSettings.Get("MONGOHQ_URL"); container.Register <CampProvider>(new CampProvider(mongoConnectionString)); }
public override void Configure(TinyIoC.TinyIoCContainer container) { base.Configure(container); container.Register <IHtmlTemplateIdStrategy>( // For compatibility with previous version of Cassette, // pathSeparatorReplacement is "-" by default (c, n) => new HtmlTemplateIdBuilder(pathSeparatorReplacement: "-") ); }
static int Main(string[] args) { TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer(); container.Register<ArgumentsModel>(new ArgumentsModel(args)); container.RegisterInterfaceImplementations("MFilesImporter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); container.RegisterInterfaceImplementations("MFilesImporter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); var program = container.Resolve<Program>(); return program.Run(); }
public void When_a_resolutionException_has_no_inner_should_return_the_resolutionException() { var tinyIoCContainer = new TinyIoC.TinyIoCContainer(); tinyIoCContainer.Register<IFoo, Foo>(); MethodThatThrows m = () => tinyIoCContainer.Resolve<IFoo>().ShouldNotBeNull(); Exception exception = StatLight.Console.Program.ResolveNonTinyIocException(m.GetException()); exception.ShouldNotBeNull(); exception.ShouldBeOfType(typeof(TinyIoC.TinyIoCResolutionException)); }
public void TinyIoCSimpleDITest() { var container = new TinyIoC.TinyIoCContainer(); container.Register<MockObject, MockObjectTiny>().AsMultiInstance(); var start = DateTime.Now; for (int i = 0; i < _iterations; i++) { var t = container.Resolve<MockObject>(); } var end = DateTime.Now; Console.WriteLine(string.Format("{0} Simple DI, Total milliseconds elapsed: {1}", "TinyIoC", (end - start).TotalMilliseconds)); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { base.ConfigureApplicationContainer(container); container.Register <IDbContextFactory, DbContextFactory <HotelAdminContext> >(); container.Register <IDbSetProvider, AspNetObjectContextAdapter>().AsMultiInstance(); container.Register <IObjectContext, AspNetObjectContextAdapter>().AsMultiInstance(); container.Register <IHotelRepository, HotelRepository>().AsMultiInstance(); container.Register <IFactTypeRepository, FactTypeRepository>().AsMultiInstance(); container.Register <IHistoryItemRepository, DummyHistoryItemRepository>().AsMultiInstance(); container.Register <IHotelService, HotelService>().AsMultiInstance(); container.Register <IFactTypeService, FactTypeService>().AsMultiInstance(); }
public void When_a_resolutionException_has_an_inner_should_return_the_innerException() { var tinyIoCContainer = new TinyIoC.TinyIoCContainer(); tinyIoCContainer.Register <IFoo, Foo2>(); MethodThatThrows m = () => tinyIoCContainer.Resolve <IFoo>().ShouldNotBeNull(); Exception exception = StatLight.Console.Program.ResolveNonTinyIocException(m.GetException()); exception.ShouldNotBeNull() .ShouldBeOfType(typeof(StatLightException)); }
/// <summary> /// HTTP ONLY /// </summary> /// <param name="url"></param> public static RpcClient Initialize(Uri url, string cerFilePath = null, WebProxy proxy = null) { var iocContainer = new TinyIoC.TinyIoCContainer(); iocContainer.Register <IWsDataSerializer, ProtoBufRpcDataSerializer>(new ProtoBufRpcDataSerializer(), "default"); iocContainer.Register <IRpcDataSerializer, HttpMultipartSerializer>(new HttpMultipartSerializer(), "default"); iocContainer.Register <IRpcHeadSerializer, JsonRpcHeadSerializer>(new JsonRpcHeadSerializer(), "default"); var _proxyFactory = new RpcDynamicProxyFactory(url, proxy, iocContainer); var websocketServer = ""; var client = new RpcClient(_proxyFactory, proxy, iocContainer); if (!string.IsNullOrEmpty(cerFilePath)) { if (!System.IO.File.Exists(cerFilePath)) { throw new Exception("the cer file you provided is not exists. " + Path.GetFileName(cerFilePath)); } client.AddCertForHttps(cerFilePath); } if (url.Scheme == ("https")) { websocketServer = url.AbsoluteUri.Replace("https://", "wss://"); if (!Certs.Any()) { throw new Exception("you should provide a cert when using https."); } } else { websocketServer = url.AbsoluteUri.Replace("http://", "ws://"); } var cb = new RemoteCertificateValidationCallback(client.RemoteCertificateValidationCallback); _proxyFactory.ServerCertificateValidationCallback = cb; _proxyFactory.websocketServer = websocketServer; return(client); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { base.ConfigureApplicationContainer(container); var mongoUrl = System.Environment.GetEnvironmentVariable("DATABASE_URL"); if (mongoUrl == null) { mongoUrl = "mongodb://localhost:27017/short_url"; } var mongoUrlStore = new MongoUrlStore(mongoUrl); container.Register <UrlStore>(mongoUrlStore); }
protected override void RegisterInstances(TinyIoC.TinyIoCContainer container, IEnumerable <Nancy.Bootstrapper.InstanceRegistration> instanceRegistrations) { base.RegisterInstances(container, instanceRegistrations); var settings = new NodeTreeCms.Cms.NodeTreeCmsSettings() { DbPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/NodeTreeCmsLiveDb"), AdminUrl = "/admin", DefaultViewPath = "Views/Default.cshtml" }; var cms = new Cms(settings); container.Register <ICms, Cms>(cms); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { base.ConfigureApplicationContainer(container); //try to register the command handlers container.Register <IAmACommandProcessor, CommandProcessor>(); container.Register <IAdaptAnInversionOfControlContainer, TinyIoCAdapter>(); container.Register <IHandleRequests <AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance(); container.Register <ITaskListRetriever, TaskListRetriever>().AsMultiInstance(); container.Register <ITasksDAO, TasksDAO>().AsMultiInstance(); container.Register <ITraceOutput, ConsoleTrace>().AsSingleton(); }
static int Main(string[] args) { TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer(); container.Register <ArgumentsModel>(new ArgumentsModel(args)); container.RegisterInterfaceImplementations("MFilesDeleter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); container.RegisterInterfaceImplementations("MFilesDeleter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); try { var program = container.Resolve <Program>(); return(program.Run()); } catch (Exception ex) { Console.WriteLine(string.Format("The following error occurred:{0}{1}", ex, Environment.NewLine)); return(1); } }
static int Main(string[] args) { TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer(); container.Register<ArgumentsModel>(new ArgumentsModel(args)); container.RegisterInterfaceImplementations("MFilesDeleter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); container.RegisterInterfaceImplementations("MFilesDeleter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes); try { var program = container.Resolve<Program>(); return program.Run(); } catch (Exception ex) { Console.WriteLine(string.Format("The following error occurred:{0}{1}", ex, Environment.NewLine)); return 1; } }
public override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer existingContainer) { base.ConfigureRequestContainer(existingContainer); existingContainer.Register <IRequestDependency, RequestDependencyClass>().AsSingleton(); }
public void Register <RegisterType>(Func <IDIContext, object, RegisterType> factory) where RegisterType : class { _container.Register <RegisterType>((c, p) => factory(this, null)); }
/// <summary> /// Registers the abstract type to be resolved by the concrete type. /// </summary> /// <typeparam name="TAbstract">The abstract type</typeparam> /// <typeparam name="TConcrete">The concrete type</typeparam> public virtual void RegisterMultiInstance <TAbstract, TConcrete>() where TAbstract : class where TConcrete : class, TAbstract { container.Register <TAbstract, TConcrete>().AsMultiInstance(); }
public virtual void Init() { TinyIoC.TinyIoCContainer ioc = TinyIoC.TinyIoCContainer.Current; ioc.Register <IDailyTimeRecordRepository, DailyTimeRecordRepository>().AsMultiInstance(); ioc.Register <IDepartmentRepository, DepartmentRepository>().AsMultiInstance(); ioc.Register <IDependentRepository, DependentRepository>().AsMultiInstance(); ioc.Register <IEducationalBackgroundRepository, EducationalBackgroundRepository>().AsMultiInstance(); ioc.Register <IEmployeeLeaveRepository, EmployeeLeaveRepository>().AsMultiInstance(); ioc.Register <IEmployeeRepository, EmployeeRepository>().AsMultiInstance(); ioc.Register <IEmploymentHistoryRepository, EmploymentHistoryRepository>().AsMultiInstance(); ioc.Register <IGlobalRuleRepository, GlobalRuleRepository>().AsMultiInstance(); ioc.Register <ILeaveEntitledRepository, LeaveEntitledRepository>().AsMultiInstance(); ioc.Register <ILeaveRepository, LeaveRepository>().AsMultiInstance(); ioc.Register <IPositionRepository, PositionRepository>().AsMultiInstance(); ioc.Register <ISchoolYearRepository, SchoolYearRepository>().AsMultiInstance(); ioc.Register <IUserRepository, UserRepository>().AsMultiInstance(); }
protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipeline) { container.Register <IAccountService, AccountService>().AsSingleton(); base.ApplicationStartup(container, pipeline); pipeline.EnableBasicAuthentication(new BasicAuthenticationConfiguration(container.Resolve <IUserValidator>(), "AgbaraVOIP")); }
public override void Configure(TinyIoC.TinyIoCContainer container) { base.Configure(container); container.Register <IHtmlTemplateIdStrategy>((c, n) => new HtmlTemplateIdBuilder()); }
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) { container.Register(typeof(IFoo), typeof(Foo)); base.ConfigureApplicationContainer(container); }