private static void BindIFhirServices(IBindingRoot kernel, List <TypeInitializer> serviceTypes, Type classType) { var serviceType = FindType(serviceTypes, classType); if (serviceType != null) { if (serviceType.Name.Equals(nameof(IFhirService))) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else if (serviceType.Name.Equals(nameof(IFhirMockupService))) { var instance = (IFhirMockupService)Activator.CreateInstance(classType); kernel.Bind <IFhirMockupService>().ToConstant(instance); _amountOfInitializedIFhirMockupServices++; } else if (serviceType.Name.Equals(nameof(AbstractStructureDefinitionService))) { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var profileValidator = new ProfileValidator(validator); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } } }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { kernel.Bind <IRepository <UserGroupEvent> >() .To <EventBriteRepository>() .InTransientScope(); kernel.Bind <IRepository <FutureTopicInfo> >() .To <IdeaScaleRepository>() .InTransientScope(); kernel.Bind <ISlackInc>() .To <SlackInCSharp>() .InTransientScope(); kernel.Bind <IRepository <NewsArticle> >() .To <NewsArticleRepository>() .InTransientScope() .WithConstructorArgument("dirPath", HostingEnvironment.MapPath("~/Content/News")); kernel.Bind(x => x .FromThisAssembly() .Select(t => typeof(ApiController).IsAssignableFrom(t) || typeof(Controller).IsAssignableFrom(t)) .BindToSelf() .Configure(c => c.InTransientScope())); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { kernel.Bind <IDbFactory>().To <DbFactory>().InSingletonScope(); kernel.Bind <IAuthProvider>().To <FormsAuthProvider>().InSingletonScope(); kernel.Bind <ICryptoProvider>().To <Sha256CryptoProvider>().InSingletonScope(); kernel.Bind <IAuctionProvider>().To <AuctionProvider>().InSingletonScope(); }
private static void BindDefaultJobRunner( IBindingRoot kernel, Action action, string jobName) { BindDefaultJobRunner(kernel, action, jobName, PausePeriod); }
private static void BindAzureBlobServices(IBindingRoot kernel) { // Bind to the Images blob container for DogController kernel.Bind<IBlobRepository>().To<K9BlobRepository>() .WhenInjectedInto<DogController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["ImageBlobContainerName"]); // Bind to the Medical Records blob container for MedicalRecordsController kernel.Bind<IBlobRepository>().To<K9BlobRepository>() .WhenInjectedInto<MedicalRecordsController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["MedicalRecordBlobContainerName"]); // Bind to the Notes blob container for MedicalRecordsController kernel.Bind<IBlobRepository>().To<K9BlobRepository>() .WhenInjectedInto<NotesController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["NotesBlobContainerName"]); }
private static void BindIFhirServices(IBindingRoot kernel, List <TypeInitializer> serviceTypes, Type classType) { var serviceType = FindType(serviceTypes, classType); if (serviceType != null) { if (serviceType.Name.Equals(nameof(IFhirService))) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else if (serviceType.Name.Equals(nameof(IFhirMockupService))) { var instance = (IFhirMockupService)Activator.CreateInstance(classType); kernel.Bind <IFhirMockupService>().ToConstant(instance); _amountOfInitializedIFhirMockupServices++; } else if (serviceType.Name.Equals(nameof(AbstractStructureDefinitionService))) { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var addResourceToIssue = ConfigurationManager.AppSettings["AddResourceResultToIssue"]; bool.TryParse(addResourceToIssue, out var boolAddResourceToIssue); var profileValidator = new ProfileValidator(validator, boolAddResourceToIssue); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } } }
private static void ConfigureLog4Net(IBindingRoot container) { log4net.Config.XmlConfigurator.Configure(); var loggerForWebSite = LogManager.GetLogger("MyQuestionnaireWebApi"); container.Bind <ILog>().ToConstant(loggerForWebSite); }
/// <summary> /// Creates the bindings for the specified services. /// </summary> /// <param name="bindingRoot">The binding root.</param> /// <param name="serviceTypes">The service types.</param> /// <param name="implementationType">The implementation type.</param> /// <returns>The syntax of the created bindings.</returns> public IEnumerable <IBindingWhenInNamedWithOrOnSyntax <object> > CreateBindings( IBindingRoot bindingRoot, IEnumerable <Type> serviceTypes, Type implementationType) { return(serviceTypes.Select(i => bindingRoot.Bind(i).To(implementationType)).ToList()); }
/// <summary> /// Handles the XElement. /// </summary> /// <param name="module">The module.</param> /// <param name="element">The element.</param> public void Handle(IBindingRoot module, XElement element) { var builder = this.bindingBuilderFactory.Create(element, module); this.childElementProcessor.ProcessAttributes(element, builder, this.excludedAttributes); this.childElementProcessor.ProcessChildElements(element, builder); }
/// <summary> /// Creates bindings using conventions /// </summary> /// <param name="kernel">The kernel for which the bindings are created.</param> /// <param name="configure">The binding convention configuration.</param> public static void Bind(this IBindingRoot kernel, Action <IFromSyntax> configure) { if (configure == null) { throw new ArgumentNullException("configure"); } #if !NO_ASSEMBLY_SCANNING var assemblyNameRetriever = new AssemblyNameRetriever(); try { var builder = new ConventionSyntax( new ConventionBindingBuilder(kernel, new TypeSelector()), new AssemblyFinder(assemblyNameRetriever), new TypeFilter(), new BindingGeneratorFactory(new BindableTypeSelector())); configure(builder); } finally { assemblyNameRetriever.Dispose(); } #else var builder = new ConventionSyntax( new ConventionBindingBuilder(kernel, new TypeSelector()), new TypeFilter(), new BindingGeneratorFactory(new BindableTypeSelector())); configure(builder); #endif }
public static void BindClassesAsSingleton( this IBindingRoot bindingRoot, IList <Type> conventionIgnore = null, params Type[] assemblies) { var list = new List <Type> { typeof(IConfigObject), typeof(IEvent), typeof(HttpServiceListener), typeof(GigyaSiloHost) }; if (conventionIgnore != null) { list.AddRange(conventionIgnore); } bindingRoot.Bind(x => { var types = x.FromAssemblyContaining(assemblies) .SelectAllClasses() .Where(t => list.All(nonSingletonType => nonSingletonType.IsAssignableFrom(t) == false)); types .BindToSelf() .Configure(c => c.InSingletonScope()); }); }
public static void BindInterfacesAsSingleton( this IBindingRoot bindingRoot, IList <Type> conventionIgnore, IList <Type> bindInterfacesInAssemblies, params Type[] assemblies) { var list = new List <Type> { typeof(IConfigObject), typeof(IEvent), typeof(IEnvironment), typeof(HttpServiceListener), typeof(GigyaSiloHost) }; if (conventionIgnore != null) { list.AddRange(conventionIgnore); } bindingRoot.Bind(x => { x.FromAssemblyContaining(assemblies) .SelectAllClasses() .Where(t => list.All(nonSingletonType => nonSingletonType.IsAssignableFrom(t) == false)) // Bind interfaces to the implementation from assemblies ( by types ) // The interfaces are from the specific assemblies ( by types as well) // The last is to avoid bind types arbitrary and isolate it to same assembly or abstraction assembly. .BindSelection((type, types) => types.Where(i => assemblies.Select(a => a.Assembly).Contains(i.Assembly) || bindInterfacesInAssemblies?.Select(a => a.Assembly).Contains(i.Assembly) == true)) .Configure(c => c.InSingletonScope()); }); }
private static void BindIFhirServices(IBindingRoot kernel, Type fhirService, Type fhidStructureDefinition, Type classType) { if (!fhirService.IsAssignableFrom(classType) && !fhidStructureDefinition.IsAssignableFrom(classType) || classType.IsInterface || classType.IsAbstract) { return; } if (fhirService.IsAssignableFrom(classType)) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var profileValidator = new ProfileValidator(validator); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } }
private static void BindAzureBlobServices(IBindingRoot kernel) { // Bind to the Images blob container for DogController kernel.Bind <IBlobRepository>().To <K9BlobRepository>() .WhenInjectedInto <DogController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["ImageBlobContainerName"]); // Bind to the Medical Records blob container for MedicalRecordsController kernel.Bind <IBlobRepository>().To <K9BlobRepository>() .WhenInjectedInto <MedicalRecordsController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["MedicalRecordBlobContainerName"]); // Bind to the Notes blob container for MedicalRecordsController kernel.Bind <IBlobRepository>().To <K9BlobRepository>() .WhenInjectedInto <NotesController>() .WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["StorageAccountConnectionString"]) .WithConstructorArgument("imageContainer", ConfigurationManager.AppSettings["NotesBlobContainerName"]); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { kernel.Bind <IHttpClient>().To <HttpClientWrapper>() .WithConstructorArgument("timeoutInSeconds", 30); kernel.Bind <IUmbracoMapper>().To <CustomMapper>().InSingletonScope(); kernel.Bind <IPageHandler>().To <PageHandler>(); kernel.Bind <ILoggingService>().To <LoggingService>().InSingletonScope(); kernel.Bind <IMetadataHandler>().To <MetadataHandler>(); kernel.Bind <INavigationHandler>().To <NavigationHandler>(); kernel.Bind <IContactPageHandler>().To <ContactPageHandler>(); kernel.Bind <IBlogPostPageHandler>().To <BlogPostPageHandler>(); kernel.Bind <IListingPageHandler>().To <ListingPageHandler>(); kernel.Bind <IErrorHandler>().To <ErrorHandler>(); kernel.Bind <IRegistrationPageHandler>().To <RegistrationPageHandler>(); kernel.Bind <IPublishingService>().To <PublishingService>(); kernel.Bind <IEmailService>().To <EmailService>() .WithConstructorArgument("emailAddress", ConfigHelper.GetSettingAsString("app.emailAddress")) .WithConstructorArgument("displayName", ConfigHelper.GetSettingAsString("app.displayName")); kernel.Bind <IJustGivingService>().To <JustGivingService>() .WithConstructorArgument("apiKey", ConfigHelper.GetSettingAsString("app.justGivingAPIKey")) .WithConstructorArgument("charityId", ConfigHelper.GetSettingAsInteger("app.justGivingCharityId")) .WithConstructorArgument("endPoint", ConfigHelper.GetSettingAsBoolean("app.justGivingTestMode") ? ConfigHelper.GetSettingAsString("app.justGivingAPISandboxEndpoint") : ConfigHelper.GetSettingAsString("app.justGivingAPIEndpoint")); // Register in request scope so that the UmbracoHelper created in constructor is only created once per request context kernel.Bind <IRootContentLocator>().To <RootContentLocator>().WhenInjectedExactlyInto <RootContentLocatorCachingProxy>().InRequestScope(); kernel.Bind <IRootContentLocator>().To <RootContentLocatorCachingProxy>(); // Register in request scope so that the UmbracoHelper created in constructor is only created once per request context kernel.Bind <IContentLocator>().To <ContentLocator>().WhenInjectedExactlyInto <ContentLocatorCachingProxy>().InRequestScope(); kernel.Bind <IContentLocator>().To <ContentLocatorCachingProxy>(); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { var r = ConfigurationManager.ConnectionStrings["RegistrarConnectionString"].ConnectionString; kernel.Bind <IRegiUserStore>() .To <RegiSqlUserStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiUserLockoutStore>() .To <RegiUserLockoutStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiRefreshTokenStore>() .To <RegiSqlRefreshTokenStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiBlockchainStore>() .To <RegiSqlBlockchainStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiUserTokenStore>() .To <RegiSqlUserTokenStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiUserFieldsStore>() .To <RegiSqlUserFieldsStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <IRegiSettingStore>() .To <RegiSqlSettingStore>() .WithConstructorArgument("connectionString", r); kernel.Bind <MultiChainHandler>().To <MultiChainHandler>().InSingletonScope(); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { kernel.Bind<IRepository<UserGroupEvent>>() .To<EventBriteRepository>() .InTransientScope(); kernel.Bind<IRepository<FutureTopicInfo>>() .To<IdeaScaleRepository>() .InTransientScope(); kernel.Bind<ISlackInc>() .To<SlackInCSharp>() .InTransientScope(); kernel.Bind<IRepository<NewsArticle>>() .To<NewsArticleRepository>() .InTransientScope() .WithConstructorArgument("dirPath", HostingEnvironment.MapPath("~/Content/News")); kernel.Bind(x => x .FromThisAssembly() .Select(t => typeof (ApiController).IsAssignableFrom(t) || typeof (Controller).IsAssignableFrom(t)) .BindToSelf() .Configure(c => c.InTransientScope())); }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes for the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { var interfaces = this.bindableTypeSelector .GetBindableInterfaces(type) .Where(interfaceType => this.filter(type, interfaceType)); return this.bindingCreator.CreateBindings(bindingRoot, interfaces, type); }
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { var list = new List<IBindingWhenInNamedWithOrOnSyntax<object>>(); if (type.IsInterface || type.IsAbstract) { return list; } IList<Type> interfaceTypes = type.GetInterfaces() .Where(t => TypeHelper.GetAllMrCMSAssemblies().Contains(t.Assembly)) .ToList(); if (interfaceTypes.Any()) { var bindingWhenInNamedWithOrOnSyntaxs = interfaceTypes.Select(interfaceType => bindingRoot.Bind(interfaceType).To(type)); list.AddRange(bindingWhenInNamedWithOrOnSyntaxs); } else { // if the type has no interfaces - bind to self list.Add(bindingRoot.Bind(type).To(type)); } return list; }
/// <summary> /// Creates the bindings for the specified services. /// </summary> /// <param name="bindingRoot">The binding root.</param> /// <param name="serviceTypes">The service types.</param> /// <param name="implementationType">The implementation type.</param> /// <returns>The syntax of the created bindings.</returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings( IBindingRoot bindingRoot, IEnumerable<Type> serviceTypes, Type implementationType) { return serviceTypes.Select(i => bindingRoot.Bind(i).To(implementationType)).ToList(); }
public static void BindExportsInAssembly(this IBindingRoot root, Assembly assembly) { root.Bind(c => c.From(assembly) .IncludingNonePublicTypes() .SelectAllClasses() .WithAttribute <ExportAttribute>() .BindWith <ExportAttributeBindingGenerator>()); }
public IEnumerable <IBindingWhenInNamedWithOrOnSyntax <object> > CreateBindings( Type type, IBindingRoot bindingRoot) { yield return(bindingRoot .Bind(type) .ToMethod(x => CreatePerson(x.Kernel.Get <IProfileService>(), type))); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { //kernel.Bind<IDataService>().To<DapperDataService>().InRequestScope(); kernel.Bind <AccountContext>().To <AccountContext>().InRequestScope(); //kernel.Bind(scan => scan.FromAssemblyContaining<IQueryProcessor>().SelectAllClasses().BindDefaultInterface()); kernel.Bind <SingleInstanceFactory>().ToMethod(ctx => t => ctx.Kernel.Get(t)); kernel.Bind(scan => scan.FromAssemblyContaining <BankAccount>().SelectAllClasses().BindAllInterfaces()); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { // Bind the application service as a singleton kernel.Bind<IApplicationService>().To<ApplicationService>().InSingletonScope(); // Bind the session handler as a singleton kernel.Bind<ISessionService>().To<SessionService>().InSingletonScope(); }
public IEnumerable <IBindingWhenInNamedWithOrOnSyntax <object> > CreateBindings( Type type, IBindingRoot bindingRoot) { yield return(bindingRoot .Bind(type) .ToMethod(ctx => GetInstance(type))); }
private static void RegisterServicesByConvention(IBindingRoot root) { root.Bind(convention => convention .FromAssembliesMatching("*") .SelectAllClasses() .InheritedFrom(typeof(IServiceDependencyMarker)) .BindDefaultInterfaces() ); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { // using System.IO; // using Ninject.Extensions.Conventions; // bind modules assemblies in bin folder var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"); kernel.Bind(a => a.FromAssembliesInPath(path).SelectAllClasses().BindDefaultInterface()); }
private static void RegisterRepositoriesByConvention(IBindingRoot root) { root.Bind(convention => convention .FromAssembliesMatching("*") .SelectAllClasses() .InheritedFrom(typeof(IRepository <>)) .BindDefaultInterfaces() ); }
/// <summary> /// Load Data Access dependency /// </summary> /// <param name="ninjectKernel">The inject Kernel parameter</param> public void LoadDependency(IBindingRoot ninjectKernel) { ////Bind business contract to corresponding business service ninjectKernel.Bind <IEmpProfilesRepository>().To <EmpProfilesDataService>(); ninjectKernel.Bind <IEmpTimeSheetRepository>().To <EmpTimeSheetDataService>(); ninjectKernel.Bind <IAdminRepository>().To <AdminDataService>(); ninjectKernel.Bind <IEmpRegisterRepository>().To <EmpRegisterDataService>(); ninjectKernel.Bind <IVendorRepository>().To <VendorDataService>(); ninjectKernel.Bind <IReportingRepository>().To <ReportingDataService>(); }
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (type.IsInterface || type.IsAbstract) { return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); } var bindings = RecursivelyBindToBaseTypes(type, bindingRoot); return bindings; }
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { var settingsName = SettingsPresistanceName(type); var settings = ReadPresistantSettings(settingsName); var proxy = CreateProxy(type, settings); return new[] { bindingRoot.Bind(type).ToConstant(proxy) }; }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { kernel.Bind <ILogger>() .ToMethod(x => new LoggerConfiguration() .WriteTo.RollingFileAlternate(@"C:\Reminders.log") .CreateLogger()); ServiceModule(kernel); RepositoryModule(kernel); }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes of the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (bindingRoot == null) { throw new ArgumentNullException("bindingRoot"); } var singleInterface = this.bindableTypeSelector.GetBindableInterfaces(type).Single(); return new[] { bindingRoot.Bind(singleInterface).To(type) }; }
public static void RegisterConstantAsAllTypes(IBindingRoot bindingRoot, object instance) { Type t = instance.GetType(); IEnumerable <Type> typesToBind = t.GetAllBaseTypes() .Concat(t.GetInterfaces()) .Except(new[] { typeof(object) }); bindingRoot.Bind(typesToBind.ToArray()).ToConstant(instance); }
public void LoadDependency(IBindingRoot ninjectKernel) { ////Bind business contract to corresponding business service ninjectKernel.Bind <IEmpProfilesService>().To <EmpProfilesService>(); ninjectKernel.Bind <IEmpTimeSheetService>().To <EmpTimeSheetService>(); ninjectKernel.Bind <IAdminService>().To <AdminService>(); ninjectKernel.Bind <IEmpRegisterService>().To <EmpRegisterService>(); ninjectKernel.Bind <IVendorService>().To <VendorService>(); ninjectKernel.Bind <IReportingService>().To <ReportingService>(); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { var dbFile = WebConfigurationManager.AppSettings["MovieDatabaseFile"]; kernel .Bind<IMovieLibrary>() .To<SimpleMovieLibrary>() .InSingletonScope() .WithConstructorArgument("databaseFile", dbFile); }
private static void BindDefaultJobRunner( IBindingRoot kernel, Action action, string jobName, TimeSpan pausePeriod) { kernel.Bind <IRunner>() .ToMethod(context => new DefaultRunner(action, jobName, JobsLogger, pausePeriod)) .InSingletonScope() .Named(jobName); }
private static void BindAllHandlerInterfaces(IBindingRoot kernel, ITypeProvider typeProvider) { typeProvider.AllHandlerTypes() .ToList() .ForEach( handlerType => handlerType.GetInterfaces() .Where(typeProvider.IsClosedGenericHandlerInterface) .ToList() .ForEach(interfaceType => kernel.Bind(interfaceType).To(handlerType).InTransientScope())); }
/// <summary> /// Creates a new binding builder and returns its binding syntax. /// </summary> /// <param name="element">The element.</param> /// <param name="module">The module.</param> /// <returns> /// The binding syntax of the created binding builder. /// </returns> public IBindingConfigurationSyntax<object> Create(XElement element, IBindingRoot module) { XAttribute serviceAttribute = element.RequiredAttribute("service"); Type service = GetTypeFromAttributeValue(serviceAttribute); VerifyElementHasExactlyOneToAttribute(element); var bindToSyntax = module.Bind(service); var syntax = HandleToAttribute(element, bindToSyntax) ?? HandleToProviderAttribute(element, bindToSyntax); return (IBindingConfigurationSyntax<object>)syntax; }
/// <summary> /// Creates a new binding builder and returns its binding syntax. /// </summary> /// <param name="element">The element.</param> /// <param name="module">The module.</param> /// <returns> /// The binding syntax of the created binding builder. /// </returns> public IBindingConfigurationSyntax <object> Create(XElement element, IBindingRoot module) { XAttribute serviceAttribute = element.RequiredAttribute("service"); Type service = GetTypeFromAttributeValue(serviceAttribute); VerifyElementHasExactlyOneToAttribute(element); var bindToSyntax = module.Bind(service); var syntax = HandleToAttribute(element, bindToSyntax) ?? HandleToProviderAttribute(element, bindToSyntax); return((IBindingConfigurationSyntax <object>)syntax); }
/// <summary>Binds a runtime mode with a particular name that can be invoked when the program starts using command line arguments.</summary> /// <typeparam name="T">The concrete type of the runtime mode to bind.</typeparam> /// <param name="root">The binding root.</param> /// <param name="name">The name of the runtime mode. This name must be specified in the command line arguments for this runtime mode to be used.</param> public static IBindingWithOrOnSyntax <T> BindRuntimeMode <T>(this IBindingRoot root, string name) where T : class, IRuntimeMode { // Create bindings for the runtime mode so it can be constructed by the container IBindingWithOrOnSyntax <T> binding = root.Bind <IRuntimeMode>().To <T>().InSingletonScope().Named(name); // Create a named binding for the runtime mode used by the main program root.Bind <INamedBinding <IRuntimeMode> >().To <LazyNamedBindingWrapper <T> >().InSingletonScope().Named(name); root.Bind <string>().ToConstant(name).WhenInjectedInto <LazyNamedBindingWrapper <T> >().Named("NAME"); root.BindLazy <T>().WhenInjectedInto <LazyNamedBindingWrapper <T> >(); return(binding); }
public IEnumerable <IBindingWhenInNamedWithOrOnSyntax <object> > CreateBindings( Type type, IBindingRoot bindingRoot) { string commandName = GetCommandName(type); Type menuItem = FindMatchingMenuItem(type.Assembly, commandName); var binding = bindingRoot.Bind(typeof(ICommand)).To(type); // this is a slight hack due to the return type limitation // but it works as longs as you dont do Configure(x => .When..) binding.WhenInjectedInto(menuItem); yield return(binding); }
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { var list = new List<IBindingWhenInNamedWithOrOnSyntax<object>>(); if (type.IsInterface || type.IsAbstract) { return list; } bindingRoot.Bind(type).ToMethod(context => GetValue(type, context)); return list; }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { if (kernel == null) throw new ArgumentNullException("kernel"); kernel.Bind<IUnitOfWork>().To<GlintContext>().InRequestScope(); kernel.Bind<IPageRepository>().To<PageRepository>().InRequestScope(); kernel.Bind<IPostRepository>().To<PostRepository>().InRequestScope(); kernel.Bind<ISettingRepository>().To<SettingRepository>().InRequestScope(); kernel.Bind<IUserRepository>().To<UserRepository>().InRequestScope(); kernel.Bind<IRoleProvider>().To<RoleRepository>().InRequestScope(); }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes for the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (bindingRoot == null) { throw new ArgumentNullException("bindingRoot"); } var binding = bindingRoot.Bind(type); var bindingConfiguration = this.instanceProvider == null ? binding.ToFactory(type) : binding.ToFactory(this.instanceProvider, type); return new[] { bindingConfiguration }; }
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { var selector = new BindableTypeSelector(); var @interface = selector.GetBindableInterfaces(type).SingleOrDefault(IsAnIReduceInterface); if (@interface == null) return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); if (typeof(ByComposition<,>).IsAssignableFrom(type)) return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); return new[] { bindingRoot.Bind(@interface).To(type) }; }
/// <summary> /// Creates a binding for a filter. /// </summary> /// <typeparam name="T">The type of the filter.</typeparam> /// <param name="kernel">The kernel.</param> /// <param name="scope">The filter scope.</param> /// <param name="order">The filter order.</param> /// <returns>The fluent syntax to specify more information for the binding.</returns> public static IFilterBindingWhenInNamedWithOrOnSyntax <T> BindFilter <T>(this IBindingRoot kernel, FilterScope scope, int?order) { var filterId = Guid.NewGuid(); var filterBinding = kernel.Bind <T>().ToSelf(); filterBinding.WithMetadata(FilterIdMetadataKey, filterId); var ninjectFilterBinding = kernel.Bind <INinjectFilter>().ToConstructor <NinjectFilter <T> >( x => new NinjectFilter <T>(x.Inject <IKernel>(), scope, order, filterId)); return(new FilterFilterBindingBuilder <T>(ninjectFilterBinding, filterBinding)); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { // Student Repository kernel.Bind<IStudentRepository>().To<DbStudentRepository>(); // Course Repository kernel.Bind<ICourseRepository>().To<DbCourseRepository>(); // Course Offering Repository kernel.Bind<ICourseOfferingRepository>().To<DbCourseOfferingRepository>(); // Services kernel.Bind<ICourseService>().To<CourseService>(); }
/// <summary> /// Initializes the main bari process /// </summary> /// <param name="output">User output interface to write messages to</param> /// <param name="parameters">User defined parameters describing the process to be performed</param> /// <param name="loader">The suite model loader implementation to be used</param> /// <param name="commandFactory">Factory for command objects</param> /// <param name="explorer">Suite explorer runner</param> /// <param name="binding">Interface to bind new dependencies</param> public MainProcess(IUserOutput output, IParameters parameters, ISuiteLoader loader, ICommandFactory commandFactory, ExplorerRunner explorer, IBindingRoot binding) { Contract.Requires(output != null); Contract.Requires(parameters != null); Contract.Requires(commandFactory != null); Contract.Requires(loader != null); Contract.Requires(explorer != null); this.output = output; this.parameters = parameters; this.loader = loader; this.commandFactory = commandFactory; this.explorer = explorer; this.binding = binding; }
private static IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> BindWithAttribute(Type type, Type baseType, IBindingRoot bindingRoot) { var bindings = new List<IBindingWhenInNamedWithOrOnSyntax<object>>(); var count = 1; var countAttribute = (InstanceAttribute) Attribute.GetCustomAttribute(type, typeof (InstanceAttribute)); if (countAttribute != null) count = countAttribute.InstanceCount; for (var i = 0; i < count; i++) { bindings.Add(bindingRoot.Bind(baseType).To(type)); } return bindings; }
private static void RegisterServices(IBindingRoot kernel) { //kernel.Bind<IMarketService>().To<MarketService>(); kernel.Bind<IDataService>().To<DataService>(); kernel.Bind<ISimulationService>().To<SimulationService>(); kernel.Bind<ISimulationServiceFactory>().To<SimulationServiceFactory>(); kernel.Bind<IProcessService>().To<ProcessService>(); kernel.Bind<ITrendlineAnalyzer>().To<TrendlineAnalyzer>(); kernel.Bind<IMarketRepository>().To<EFMarketRepository>(); kernel.Bind<IDataRepository>().To<EFDataRepository>(); //kernel.Bind<ICompanyRepository>().To<FakeCompanyRepository>(); //kernel.Bind<IMarketRepository>().To<FakeMarketRepository>(); //kernel.Bind<IDataRepository>().To<FakeDataRepository>(); }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes for the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (type == null) { throw new ArgumentNullException("type"); } if (type.IsInterface || type.IsAbstract) { return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); } var interfaces = this.bindableTypeSelector.GetBindableInterfaces(type); var baseTypes = this.bindableTypeSelector.GetBindableBaseTypes(type); var selectedTypes = this.Selector.Invoke(type, interfaces.Union(baseTypes)); return this.bindingCreator.CreateBindings(bindingRoot, selectedTypes, type); }
private static IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> RecursivelyBindToBaseTypes(Type type, IBindingRoot bindingRoot) { var baseType = type.BaseType; var bindings = new List<IBindingWhenInNamedWithOrOnSyntax<object>>(); if (baseType == null) return bindings; bindings.AddRange(BindWithAttribute(type, type.BaseType, bindingRoot)); if (!ShouldBeBound(baseType)) return bindings; var ancestor = baseType.BaseType; while (ancestor != null && ShouldBeBound(ancestor)) { bindings.AddRange(BindWithAttribute(type, ancestor, bindingRoot)); ancestor = ancestor.BaseType; } return bindings; }
private static void AddBindings(IBindingRoot container) { ConfigureLog4Net(container); //Add Other bindings here //container.Bind<ISomthing>().To<Somthing>(); //The logging tools container.Bind<IExceptionMessageFormatter>().To<ExceptionMessageFormatter>(); container.Bind<IActionLogHelper>().To<ActionLogHelper>(); container.Bind<IActionExceptionHandler>().To<ActionExceptionHandler>(); //Db Context container.Bind<IDbContext>().To<MyQuestionnaireDbContext>().InRequestScope(); //UserManagerFactory //ConfigureUserManagerFactory(container); //Mappings container.Bind<IOpenEndedQuestionMap>().To<OpenEndedQuestionMap>(); }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes for the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (type == null) { throw new ArgumentNullException("type"); } if (bindingRoot == null) { throw new ArgumentNullException("bindingRoot"); } if (type.IsInterface || type.IsAbstract) { return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); } return new[] { bindingRoot.Bind(type.BaseType).To(type) }; }
private IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> RecursivelyBindToBaseTypes(Type type, IBindingRoot bindingRoot) { Type baseType = type.BaseType; var bindings = new List<IBindingWhenInNamedWithOrOnSyntax<object>>(); if (baseType != null) { bindings.Add(bindingRoot.Bind(baseType).To(type)); if (ShouldBeBound(baseType)) { var ancestor = baseType.BaseType; while (ancestor != null && ShouldBeBound(ancestor)) { bindings.Add(bindingRoot.Bind(ancestor).To(type)); ancestor = ancestor.BaseType; } } } return bindings; }
/// <summary> /// Creates the bindings for a type. /// </summary> /// <param name="type">The type for which the bindings are created.</param> /// <param name="bindingRoot">The binding root that is used to create the bindings.</param> /// <returns> /// The syntaxes for the created bindings to configure more options. /// </returns> public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot) { if (type == null) { throw new ArgumentNullException("type"); } if (bindingRoot == null) { throw new ArgumentNullException("bindingRoot"); } if (type.IsInterface || type.IsAbstract) { return Enumerable.Empty<IBindingWhenInNamedWithOrOnSyntax<object>>(); } var bindings = RecursivelyBindToBaseTypes(type, bindingRoot); return bindings; }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> public static void RegisterServices(IBindingRoot kernel) { var url = ConfigurationManager.AppSettings["RAVENHQ_CONNECTION_STRING"].Split('=')[1]; if(url.ToUpper().IndexOf("APPHARBOR", System.StringComparison.Ordinal)!=-1) { url = String.Format("{0}; ApiKey=067d4f3d-d26a-4dc9-b362-e04a5a92ee8a", url); } kernel.Bind<IDocumentStore>() .ToMethod(context => { var documentStore = new DocumentStore { Url = "https://1.ravenhq.com/databases/AppHarbor_7a9dd280-17f7-439b-aea4-36467fd9ef1d", ApiKey = "067d4f3d-d26a-4dc9-b362-e04a5a92ee8a" }; return documentStore.Initialize(); }) .InTransientScope(); kernel.Bind<IDocumentSession>().ToMethod(context => context.Kernel.Get<IDocumentStore>().OpenSession()).InRequestScope(); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IBindingRoot kernel) { // Bind The Site Context kernel.Bind<SiteDbContext, DbContext>().To<SiteDbContext>().InRequestScope(); // Bind View Factories kernel.Bind<AdminViewFactories>().ToSelf().InSingletonScope(); kernel.Bind<CustomerViewFactories>().ToSelf().InSingletonScope(); // Bind Repositories kernel.Bind<IAdminRepository>().To<AdminRepository>().InRequestScope(); kernel.Bind<ICustomerRepository>().To<CustomerRepository>().InRequestScope(); // Bind the User Store kernel.Bind<IUserStore<ApplicationUser>>().To<UserStore<ApplicationUser>>() .InRequestScope(); // Bind the Application Manager kernel.Bind<ApplicationUserManager>() .ToMethod(x => HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>()) .InRequestScope(); // Bind the Signing Manager kernel.Bind<ApplicationSignInManager>() .ToMethod(x => HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager>()) .InRequestScope(); // Bind the Authentication Manager kernel.Bind<IAuthenticationManager>() .ToMethod(x => HttpContext.Current.GetOwinContext().Authentication) .InRequestScope(); }