/// <summary> /// Sets the object container. /// </summary> /// <param name="container">The container.</param> public static void Init(IIoc container) { lock (_syncRoot) { _container = container; } }
public TransientResolver(IIoc ioc, Type toresolveType) { this.Resolve = () => { // get ctor var ctor = toresolveType.GetConstructors().FirstOrDefault(); if (ctor == null) { throw new Exception($"No ctor found for type {toresolveType.FullName}!"); } // get ctor params var ctorParams = ctor.GetParameters(); if (!ctorParams.Any()) { return(Activator.CreateInstance(toresolveType)); } else { // recursive resolve var parameters = new List <object>(ctorParams.Length); foreach (var parameterInfo in ctorParams) { parameters.Add(ioc.Resolve(parameterInfo.ParameterType)); } return(ctor.Invoke(parameters.ToArray())); } }; }
/// <summary> /// 注册 /// </summary> /// <typeparam name="ServiceType"></typeparam> /// <typeparam name="ImplementationType"></typeparam> /// <param name="serviceLifetime"></param> /// <returns></returns> public static IIoc AddType <ServiceType, ImplementationType>(this IIoc ioc, ServiceLifetime serviceLifetime, InjectType injectMode, object[] parameters = null) where ServiceType : class where ImplementationType : class { ioc.AddType(typeof(ServiceType), typeof(ImplementationType), serviceLifetime, injectMode, parameters); return(ioc); }
/// <summary> /// 注册 /// </summary> /// <typeparam name="ServiceType"></typeparam> /// <typeparam name="ImplementationType"></typeparam> /// <returns></returns> public static IIoc AddTransient <ServiceType, ImplementationType>(this IIoc ioc, object[] parameters = null) where ServiceType : class where ImplementationType : class { ioc.AddTransient(typeof(ServiceType), typeof(ImplementationType), parameters); return(ioc); }
public void RegisterMappings(IIoc ioc) { var sampleDll = new IocRegisterSampleDll(); sampleDll.RegisterMappings(ioc); ioc.Register<IHelperTool, HelperTool>(); }
/// <summary> /// 添加单例判断条件 /// </summary> /// <typeparam name="ConditionType">需要特殊配置单例条件的类型</typeparam> /// <param name="condition">输入参数:当前实例。输出参数:返回True为创建新对象</param> /// <returns></returns> public static IIoc AddSingletonCondition <ConditionType>(this IIoc ioc, Func <ConditionType, bool> condition) where ConditionType : class { ioc.AddSingletonCondition(typeof(ConditionType), objectInstance => { return(condition(objectInstance as ConditionType)); }); return(ioc); }
public static IIoc Configure <T>(this IIoc ioc, IAppConfig appConfig) where T : class, new() { appConfig.Binding <T>(obj => { ioc.AddSingleton <IAppOptions <T> >(new AppOptions <T>(obj)); }); return(ioc); }
public void RegisterMappings(IIoc ioc) { var sampleDll = new IocRegisterSampleDll(); sampleDll.RegisterMappings(ioc); ioc.Register <IHelperTool, HelperTool>(); }
public MainWindow() { InitializeComponent(); _ioc = IocMaker.NewIocWith(new List <IIocRegister> { new IocRegisterSampleWpf(), this }); _sampleType2 = _ioc.Resolve <ISampleType2>(); _configData = _ioc.Resolve <IConfigData>(); }
public MainWindow() { InitializeComponent(); _ioc = IocMaker.NewIocWith(new List<IIocRegister> { new IocRegisterSampleWpf(), this }); _sampleType2 = _ioc.Resolve<ISampleType2>(); _configData = _ioc.Resolve<IConfigData>(); }
public UploadNewVersionPresenter(IMetaData metaData, IChecksum checksum, IFileManager fileManager, IMessageService messageService, IFileValidator fileValidator, IFormFactory <IUploadNewVersionView> formFactory, IIoc ioc, INetworkPathInfo networkPathInfo) { _formFactory = formFactory; _ioc = ioc; _networkPathInfo = networkPathInfo; _messageService = messageService; _fileValidator = fileValidator; _checksum = checksum; _metaData = metaData; _fileManager = fileManager; _networkPath = _networkPathInfo.GetPathNeworkDirectory(); }
public DatabaseDetailsPresenter(IMetaData sqlMetaDataInfo, IMetaData sqlMetaDataDetails, IIoc ioc, IFormFactory <IDatabaseDetailsView> formFactory, DownloadSelectedVersionPresenter downloadSelectedVersionPresenter, UploadNewVersionPresenter uploadNewVersionPresenter, IUserAccessCredentials userAccessCredentials, INetworkPathInfo networkPathInfo, INetworkConnection networkConnection) { _sqlMetaDataDetails = sqlMetaDataDetails; _formFactory = formFactory; _downloadSelectedVersionPresenter = downloadSelectedVersionPresenter; _uploadNewVersionPresenter = uploadNewVersionPresenter; _userAccessCredentials = userAccessCredentials; _networkPathInfo = networkPathInfo; _networkConnection = networkConnection; _sqlMetaDataInfo = sqlMetaDataInfo; _ioc = ioc; }
public SingleInstanceResolver(IIoc ioc, Type type) { Resolve = () => { // first resolve. Using transient resolver if (_singleInstance == null) { var transientResolver = new TransientResolver(ioc, type); _singleInstance = transientResolver.Resolve(); } return(_singleInstance); }; }
public static async void Main() { #if TEST return; #endif #if !DEBUG NavigationUtility.VirtualDirectory = "realworld.spaf"; // virtual dir for release environment #endif Container = new BridgeIoc(); ContainerConfig(); // config container var mainVm = Container.Resolve <MainViewModel>(); await mainVm.Start(); Container.Resolve <INavigator>().InitNavigation(); // init navigation }
/// <summary> /// 注册 /// </summary> /// <param name="serviceLifetime"></param> /// <param name="assemblies"></param> /// <returns></returns> public static IIoc RegisterTypeByAssembly(this IIoc ioc, ServiceLifetime serviceLifetime, InjectType injectMode, params Assembly[] assemblies) { if (assemblies.Length <= 0) { return(ioc); } Type iocIgnoreAttributeType = typeof(IocIgnoreAttribute); Type liftTimeAttributeType = typeof(LiftTimeAttribute); Type injectType = typeof(InjectAttribute); ServiceLifetime liftTime; InjectType injectModeTmp; foreach (var item in assemblies) { foreach (var item1 in item.ExportedTypes) { if (item1.IsClass && !item1.IsAbstract) { if (item1.IsDefined(iocIgnoreAttributeType)) { continue; } if (item1.IsDefined(liftTimeAttributeType)) { var liftTimeAttribute = item1.GetCustomAttribute <LiftTimeAttribute>(); liftTime = liftTimeAttribute.ServiceLifetime; } else { liftTime = serviceLifetime; } if (item1.IsDefined(injectType)) { var obj = item1.GetCustomAttribute <InjectAttribute>(); injectModeTmp = obj.InjectMode; } else { injectModeTmp = injectMode; } ioc.AddType(item1, item1, liftTime, injectModeTmp); } } } return(ioc); }
public DatabasesListPresenter(IChecksum checksum, IUserAccessCredentials userAccessCredentials, IFileManager fileManager, IMetaData metaData, IIoc ioc, DatabaseDetailsPresenter databaseDetailsPresenter, LoginPresenter loginPresenter, IFormFactory <IDatabasesListView> formFactory, INetworkConnection networkConnection, INetworkPathInfo networkPathInfo) { _databaseDetailsPresenter = databaseDetailsPresenter; _loginPresenter = loginPresenter; _checksum = checksum; _userAccessCredentials = userAccessCredentials; _fileManager = fileManager; _metaData = metaData; _ioc = ioc; _formFactory = formFactory; _networkConnection = networkConnection; _networkPathInfo = networkPathInfo; _view = _formFactory.CreateDatabasesListForm(); _resumableFileManager = _fileManager as IResumableFileManager; _cancellationTokenSource = new CancellationTokenSource(); _networkPath = _networkPathInfo.GetPathNeworkDirectory(); }
public void RegisterMappings(IIoc ioc) { ioc.Register<ISampleType, SampleType>(); ioc.Register<ISampleType2, SampleType2>(); }
public FormFactory(IIoc ioc) { _ioc = ioc; }
public void RegisterMappings(IIoc ioc) { ioc.Register<IConfigData>(new ConfigData { ANumber = 1 }); }
public void Initilize(IIoc ioc) { _iocResolver = ioc; }
/// <summary> /// 注册 /// </summary> /// <param name="serviceType"></param> /// <param name="implementationType"></param> /// <returns></returns> public static IIoc AddTransient(this IIoc ioc, Type serviceType, Type implementationType, object[] parameters = null) { ioc.AddType(serviceType, implementationType, ServiceLifetime.Transient, InjectType.Constructor, parameters); return(ioc); }
/// <summary> /// Initializes a new instance of the <see cref="MessageContext"/> class. /// </summary> /// <param name="ioc">The ioc.</param> public MessageContext(IIoc ioc) { _ioc = ioc; _containerScope = _ioc.CreateContext(); MessageInfo = new MessageInfo(); }
/// <summary> /// Creates the specified ioc. /// </summary> /// <param name="ioc">The ioc.</param> public static void Create(IIoc ioc) { Instance = new ContextManager(ioc); }
/// <summary> /// 注册 /// </summary> /// <param name="serviceType"></param> /// <param name="implementationTypeInstance"></param> /// <returns></returns> public static IIoc AddSingleton(this IIoc ioc, Type serviceType, object implementationTypeInstance, object[] parameters = null) { ioc.AddType(serviceType, implementationTypeInstance, ServiceLifetime.Singleton, InjectType.Constructor, parameters); return(ioc); }
public ApplicationBuilder UseIocContainer(IIoc container) { ApplicationServices.IocContainer = container; return(this); }
/// <summary> /// 注册 /// </summary> /// <param name="assemblies"></param> /// <returns></returns> public static IIoc RegisterTypeByAssembly(this IIoc ioc, params Assembly[] assemblies) { ioc.RegisterTypeByAssembly(ServiceLifetime.Transient, InjectType.Constructor, assemblies); return(ioc); }
public void RegisterMappings(IIoc ioc) { ioc.Register <IConfigData>(new ConfigData { ANumber = 1 }); }
/// <summary> /// 注册 /// </summary> /// <typeparam name="ServiceType"></typeparam> /// <param name="implementationTypeInstance"></param> /// <returns></returns> public static IIoc AddTransient <ServiceType>(this IIoc ioc, ServiceType implementationTypeInstance, object[] parameters = null) where ServiceType : class { ioc.AddType(implementationTypeInstance, ServiceLifetime.Transient, InjectType.Constructor, parameters); return(ioc); }
/// <summary> /// 注册 /// </summary> /// <typeparam name="ServiceType"></typeparam> /// <returns></returns> public static IIoc AddSingleton <ServiceType>(this IIoc ioc, object[] parameters = null) where ServiceType : class { ioc.AddType <ServiceType, ServiceType>(ServiceLifetime.Singleton, InjectType.Constructor, parameters); return(ioc); }
public void RegisterMappings(IIoc ioc) { ioc.Register <ISampleType, SampleType>(); ioc.Register <ISampleType2, SampleType2>(); }
/// <summary> /// Initializes a new instance of the <see cref="ContextManager"/> class. /// </summary> /// <param name="ioc">The ioc.</param> private ContextManager(IIoc ioc) { _ioc = ioc; }