public static void RegisterFakeProviders(this IDependencyRegistrator dependencyRegistrator)
        {
            var assembliesProvider = new CustomAssemblySourceProvider(PlatformProvider.Current.GetRootPath(),
                                                                      new[] { Consts.ContractsAssemblyEnding, Consts.FakeAssemblyEnding });
            var allAssemblies         = assembliesProvider.Assemblies.ToArray();
            var contractTypes         = allAssemblies.FindContractTypes();
            var fakeTypes             = allAssemblies.FindFakeTypes();
            var contractToFakeMatches = new Dictionary <Type, Type>();

            foreach (var type in fakeTypes)
            {
                var contractType =
                    contractTypes.FirstOrDefault(
                        t => t.Name == "I" + type.Name.Replace(Consts.FakePrefix, string.Empty));
                if (contractType != null)
                {
                    contractToFakeMatches.Add(contractType, type);
                }
            }

            foreach (var contractToFakeMatch in contractToFakeMatches)
            {
                dependencyRegistrator.RegisterSingleton(contractToFakeMatch.Key, contractToFakeMatch.Value);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Registers the instance of the dependency.v
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencyType">The type of dependency.</param>
 /// <param name="instance">The instance of dependency.</param>
 public static IDependencyRegistrator AddInstance(this IDependencyRegistrator dependencyRegistrator,
                                                  Type dependencyType,
                                                  object instance)
 {
     dependencyRegistrator.RegisterInstance(dependencyType, instance);
     return(dependencyRegistrator);
 }
Ejemplo n.º 3
0
        public static IDependencyRegistrator RegisterMvvm(this IDependencyRegistrator service)
        {
            service.Register <IDialogManager>(x => new DialogManager());


            return(service);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Registers the collection of the dependencies.
 /// </summary>
 /// <typeparam name="TDependency">The type of the dependency.</typeparam>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencies">The dependencies.</param>
 public static IDependencyRegistrator AddCollection <TDependency>(
     this IDependencyRegistrator dependencyRegistrator, IEnumerable <TDependency> dependencies)
     where TDependency : class
 {
     dependencyRegistrator.RegisterCollection(dependencies);
     return(dependencyRegistrator);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Registers dependency in a transient lifetime style using fluent API.
 /// </summary>
 /// <typeparam name="TDependency">The type of the dependency declaration.</typeparam>
 /// <typeparam name="TImplementation">The type of the dependency implementation.</typeparam>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencyCreator">Dependency creator delegate.</param>
 public static IDependencyRegistrator AddTransient <TDependency, TImplementation>(
     this IDependencyRegistrator dependencyRegistrator, Func <TImplementation> dependencyCreator)
     where TImplementation : class, TDependency
 {
     dependencyRegistrator.RegisterTransient(dependencyCreator);
     return(dependencyRegistrator);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Registers the collection of the dependencies.
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencyType">The type of the dependency.</param>
 /// <param name="dependencyTypes">The dependency types.</param>
 public static IDependencyRegistrator AddCollection(this IDependencyRegistrator dependencyRegistrator,
                                                    Type dependencyType,
                                                    IEnumerable <Type> dependencyTypes)
 {
     dependencyRegistrator.RegisterCollection(dependencyType, dependencyTypes);
     return(dependencyRegistrator);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Registers dependency in a transient lifetime style using fluent API.
 /// </summary>
 /// <typeparam name="TDependency">The type of the dependency.</typeparam>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencyCreator">Dependency creator delegate.</param>
 public static IDependencyRegistrator AddTransient <TDependency>(
     this IDependencyRegistrator dependencyRegistrator,
     Func <TDependency> dependencyCreator) where TDependency : class
 {
     dependencyRegistrator.RegisterTransient(dependencyCreator);
     return(dependencyRegistrator);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Registers dependency as a singleton using fluent API.
 /// </summary>
 /// <typeparam name="TDependency">The type of the dependency.</typeparam>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 public static IDependencyRegistrator AddSingleton <TDependency>(
     this IDependencyRegistrator dependencyRegistrator)
     where TDependency : class
 {
     dependencyRegistrator.RegisterSingleton <TDependency>();
     return(dependencyRegistrator);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Registers the modules into the IoC container.
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="contractType">The type of the contract.</param>
 /// <param name="modules">The collection of modules.</param>
 public static void RegisterModules(
     IDependencyRegistrator dependencyRegistrator,
     Type contractType,
     IEnumerable <ICompositionModule> modules)
 {
     RegisterCollection(dependencyRegistrator, contractType, modules.Select(t => t.GetType()));
 }
        public override void Config(IDependencyRegistrator container, DependencyScope scope = DefaultDependencyScope)
        {
            // Unit of Work
            container.RegisterType <FamilyUnitOfWork, IFamilyUnitOfWork>(scope);

            // Managers
            container.RegisterType <FilesManager, IFilesManager>(scope);
            container.RegisterType <PersonsManager, IPersonsManager>(scope);
            container.RegisterType <ArticlesManager, IArticlesManager>(scope);
            container.RegisterType <MaterialsManager, IMaterialsManager>(scope);

            // Services
            container.RegisterType <VideoConverter, IVideoConverter>(scope);

            // Domain Events Handlers
            container.RegisterType <NotificationsHandlerService, IDomainEventHandler <RegistrationRequestedEvent> >(scope);
            container.RegisterType <NotificationsHandlerService, IDomainEventHandler <ManagerCreatedEvent> >(scope);
            container.RegisterType <NotificationsHandlerService, IDomainEventHandler <GuestCreatedEvent> >(scope);
            container.RegisterType <NotificationsHandlerService, IDomainEventHandler <PasswordRecoveryRequestedEvent> >(scope);
            container.RegisterType <NotificationsHandlerService, IDomainEventHandler <PasswordChangedEvent> >(scope);

            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialAddedToArticleEvent> >(scope);
            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialDeletedEvent> >(scope);
            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialFileChangedEvent> >(scope);
            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialTransformEvent> >(scope);
            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialInfoChangedEvent> >(scope);
            container.RegisterType <MaterialModificationService, IDomainEventHandler <MaterialSavedEvent> >(scope);
        }
Ejemplo n.º 11
0
 public Bootstrapper(IDependencyRegistrator dependencyRegistrator) : base(dependencyRegistrator)
 {
     // ReSharper disable once ArrangeThisQualifier
     this.registratorExtensibilityAspect = new ExtensibilityAspect <IHaveRegistrator>(this);
     // ReSharper disable once ArrangeThisQualifier
     UseAspect(this.registratorExtensibilityAspect);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates an instance of <see cref="BootstrapperBase"/>
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 public BootstrapperBase(IDependencyRegistrator dependencyRegistrator)
 {
     Registrator          = dependencyRegistrator;
     _platformAspect      = new PlatformAspect();
     _discoveryAspect     = new DiscoveryAspect(CompositionOptions);
     _modularityAspect    = new ModularityAspect(_discoveryAspect, CompositionOptions);
     _extensibilityAspect = new ExtensibilityAspect <BootstrapperBase>(this);
 }
Ejemplo n.º 13
0
 protected override void ConfigureServices(IDependencyRegistrator registrator)
 {
     registrator
     .RegisterApplication(this)
     .RegisterView <MainWindow, MainWindowViewModel>()
     .RegisterMvvm()
     ;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Registers collection of modules into the IoC container.
        /// </summary>
        /// <typeparam name="TModule">The type of the module.</typeparam>
        /// <param name="dependencyRegistrator">The dependency registrator.</param>
        /// <param name="modules">The collection of modules.</param>
        public static void RegisterModules <TModule>(
            IDependencyRegistrator dependencyRegistrator,
            IEnumerable <ICompositionModule> modules) where TModule : class
        {
            var typedModules = modules.OfType <TModule>().ToArray();

            dependencyRegistrator.RegisterCollection(typedModules);
        }
Ejemplo n.º 15
0
        public static IDependencyRegistrator RegisterView <TView, TViewModel>(this IDependencyRegistrator service)
            where TView : FrameworkElement
            where TViewModel : class, INotifyPropertyChanged
        {
            service.Register <TView>();
            service.Register <TViewModel>();

            return(service);
        }
Ejemplo n.º 16
0
 public Bootstrapper(IDependencyRegistrator dependencyRegistrator) : base(dependencyRegistrator)
 {
     _thisExtensibilityAspect = new ExtensibilityAspect <Bootstrapper>(this);
     UseAspect(_thisExtensibilityAspect);
     _registratorExtensibilityAspect = new ExtensibilityAspect <IHaveRegistrator>(this);
     UseAspect(_registratorExtensibilityAspect);
     _discoveryAspect = new DiscoveryAspect(CompositionOptions, GetType());
     UseAspect(_discoveryAspect);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Registers types as their abstractions using singleton lifetime style
 /// The assemblies are inspected using [IDependency]--[Dependency] naming convention
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="contractsAssembly">The assembly which contains the contracts/abstractions</param>
 /// <param name="implementationsAssembly">The assembly which contains the implementations.</param>
 /// <returns></returns>
 public static IDependencyRegistrator RegisterAutomagically(
     this IDependencyRegistrator dependencyRegistrator,
     Assembly contractsAssembly,
     Assembly implementationsAssembly)
 {
     return(dependencyRegistrator.RegisterAutomagically(
                (d, serviceType, implementationType) => d.RegisterSingleton(serviceType, implementationType),
                contractsAssembly,
                implementationsAssembly));
 }
Ejemplo n.º 18
0
        public FormsApp(IDependencyRegistrator dependencyRegistrator)
        {
            Initialize();

            _dependencyRegistrator = dependencyRegistrator;

            //TODO: Move all registrations to modules
            _dependencyRegistrator.RegisterTransient <ShellViewModel>();
            _dependencyRegistrator.RegisterTransient <MainViewModel>();

            DisplayRootViewFor <ShellViewModel>();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Registers the view models.
        /// </summary>
        /// <param name="dependencyRegistrator">The dependency registrator.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="excludedTypes">The types to be excluded from the registration.</param>
        public static void RegisterViewModels(
            this IDependencyRegistrator dependencyRegistrator,
            IEnumerable <Assembly> assemblies,
            IEnumerable <Type> excludedTypes)
        {
            var viewModelTypes = assemblies
                                 .SelectMany(assembly => assembly.ExportedTypes)
                                 .Where(type => excludedTypes.Contains(type) == false && type.Name.EndsWith("ViewModel"))
                                 .Where(type => type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(INotifyPropertyChanged)));

            viewModelTypes.Aggregate(dependencyRegistrator, (seed, next) => seed.AddTransient(next, next));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Registers the collection of types that implement the specified contract
        /// into the IoC container.
        /// </summary>
        /// <param name="dependencyRegistrator">The dependency registrator.</param>
        /// <param name="contractType">The type of the contract.</param>
        /// <param name="types">The types.</param>
        public static void RegisterCollection(
            IDependencyRegistrator dependencyRegistrator,
            Type contractType,
            IEnumerable <Type> types)
        {
            var typeInfo     = contractType.GetTypeInfo();
            var serviceTypes = types.Select(t => t.GetTypeInfo()).Where(t =>
                                                                        t.IsInterface == false && t.IsAbstract == false &&
                                                                        typeInfo.IsAssignableFrom(t)).Select(t => t.AsType());

            dependencyRegistrator.RegisterCollection(contractType, serviceTypes);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Registers already constructed instances into the container.
        /// </summary>
        /// <param name="registrator">The dependency registrator.</param>
        /// <param name="instances">The constructed instances collection.</param>
        /// <param name="withoutDisposalTracking">If it's set to true the container will exclude the instance from the disposal tracking.</param>
        /// <returns>The <see cref="IStashboxContainer"/> which on this method was called.</returns>
        public static IStashboxContainer RegisterInstances <TFrom>(this IDependencyRegistrator registrator,
                                                                   IEnumerable <TFrom> instances, bool withoutDisposalTracking = false)
            where TFrom : class
        {
            Shield.EnsureNotNull(instances, nameof(instances));

            foreach (var instance in instances)
            {
                registrator.RegisterInstance(instance, withoutDisposalTracking: withoutDisposalTracking);
            }

            return((IStashboxContainer)registrator);
        }
        public static IDependencyRegistrator RegisterBuilders(this IDependencyRegistrator dependencyRegistrator)
        {
            var assembliesProvider = new CustomAssemblySourceProvider(PlatformProvider.Current.GetRootPath(),
                                                                      new[] { Consts.BuildersAssemblyEnding });
            var assemblies    = assembliesProvider.Assemblies.ToArray();
            var buildersTypes = assemblies.FindBuildersTypes();

            foreach (var type in buildersTypes)
            {
                var instance = BuilderFactory.CreateBuilderInstance(type);
                dependencyRegistrator.RegisterInstance(type, instance);
            }
            return(dependencyRegistrator);
        }
 private static void RegisterTransientDescriptor(IDependencyRegistrator container, ServiceDescriptor descriptor)
 {
     if (descriptor.ImplementationType != null)
     {
         container.Register(descriptor.ServiceType, descriptor.ImplementationType);
     }
     else if (descriptor.ImplementationFactory != null)
     {
         container.Register(descriptor.ServiceType, context => context
                            .WithFactory(c => descriptor.ImplementationFactory(c.Resolve <IServiceProvider>())));
     }
     else
     {
         container.RegisterInstance(descriptor.ServiceType, descriptor.ImplementationInstance);
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Registers the collection of types that implement the specified contract
        /// into the dependency registrator.
        /// </summary>
        /// <param name="dependencyRegistrator">The dependency registrator.</param>
        /// <param name="types">The types.</param>
        /// <param name="allowExactMatchOnly"></param>
        public static IDependencyRegistrator RegisterCollection <TService>(
            this IDependencyRegistrator dependencyRegistrator,
            IEnumerable <Type> types,
            bool allowExactMatchOnly = false) where TService : class
        {
            IEnumerable <Type> eligibleTypes;

            if (allowExactMatchOnly)
            {
                var typeInfo = typeof(TService).GetTypeInfo();
                eligibleTypes = GetEligibleTypes(types, typeInfo);
            }
            else
            {
                eligibleTypes = types;
            }
            dependencyRegistrator.RegisterCollection <TService>(eligibleTypes);
            return(dependencyRegistrator);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Registers the collection of types that implement the specified contract
        /// into the dependency registrator.
        /// </summary>
        /// <param name="dependencyRegistrator">The dependency registrator.</param>
        /// <param name="contractType">The type of the contract.</param>
        /// <param name="types">The types.</param>
        /// <param name="allowExactMatchOnly"></param>
        public static IDependencyRegistrator RegisterCollection(
            IDependencyRegistrator dependencyRegistrator,
            Type contractType,
            IEnumerable <Type> types,
            bool allowExactMatchOnly = false)
        {
            IEnumerable <Type> eligibleTypes;

            if (allowExactMatchOnly)
            {
                var typeInfo = contractType.GetTypeInfo();
                eligibleTypes = GetEligibleTypes(types, typeInfo);
            }
            else
            {
                eligibleTypes = types;
            }
            dependencyRegistrator.RegisterCollection(contractType, eligibleTypes);
            return(dependencyRegistrator);
        }
        /// <summary>
        /// Registers service descriptors into the container.
        /// </summary>
        /// <param name="container">The <see cref="IStashboxContainer"/>.</param>
        /// <param name="services">The service descriptors.</param>
        public static void RegisterServiceDescriptors(this IDependencyRegistrator container, IEnumerable <ServiceDescriptor> services)
        {
            foreach (var descriptor in services)
            {
                switch (descriptor.Lifetime)
                {
                case ServiceLifetime.Scoped:
                    RegisterScopedDescriptor(container, descriptor);
                    break;

                case ServiceLifetime.Singleton:
                    RegisterSingletonDescriptor(container, descriptor);
                    break;

                case ServiceLifetime.Transient:
                    RegisterTransientDescriptor(container, descriptor);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(descriptor.Lifetime));
                }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates an instance of the <see cref="LogoFXApplication{TRootViewModel}"/>
        /// </summary>
        /// <param name="bootstrapper">The app bootstrapper.</param>
        /// <param name="viewFirst">Use true to enable built-in navigation, false otherwise. The default value is true.</param>
        public LogoFXApplication(
            BootstrapperBase bootstrapper,
            bool viewFirst = true)
        {
            Initialize();

            bootstrapper
            .Use(new RegisterCompositionModulesMiddleware <BootstrapperBase>())
            .Use(new RegisterRootViewModelMiddleware <BootstrapperBase, TRootViewModel>())
            .Initialize();

            _dependencyRegistrator = bootstrapper.Registrator;

            if (viewFirst)
            {
                var viewType = ViewLocator.LocateTypeForModelType(typeof(TRootViewModel), null, null);
                DisplayRootView(viewType);
            }
            else
            {
                //Default navigation does not work in this case
                DisplayRootViewFor <TRootViewModel>();
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of <see cref="BuilderRegistrationService"/>.
 /// </summary>
 /// <param name="dependencyRegistrator">The dependency registrator.</param>
 /// <param name="dependencyResolver">The dependency resolver.</param>
 public BuilderRegistrationService(
     IDependencyRegistrator dependencyRegistrator,
     IDependencyResolver dependencyResolver)
     : base(dependencyRegistrator, dependencyResolver)
 {
 }
 /// <summary>
 /// Registers a type with scoped lifetime.
 /// </summary>
 /// <typeparam name="TTo">Type that will be returned.</typeparam>
 /// <param name="registrator">The dependency registrator.</param>
 /// <param name="name">The name of the registration.</param>
 /// <returns>The <see cref="IStashboxContainer"/> which on this method was called.</returns>
 public static IStashboxContainer RegisterScoped <TTo>(this IDependencyRegistrator registrator, object name = null)
     where TTo : class =>
 registrator.RegisterType <TTo>(context => context.WithName(name).WithScopedLifetime());
 /// <summary>
 /// Registers a type with scoped lifetime.
 /// </summary>
 /// <param name="typeFrom">Type that will be requested.</param>
 /// <param name="typeTo">Type that will be returned.</param>
 /// <param name="registrator">The dependency registrator.</param>
 /// <param name="name">The name of the registration.</param>
 /// <returns>The <see cref="IStashboxContainer"/> which on this method was called.</returns>
 public static IStashboxContainer RegisterScoped(this IDependencyRegistrator registrator, Type typeFrom, Type typeTo, object name = null) =>
 registrator.RegisterType(typeFrom, typeTo, context => context.WithName(name).WithScopedLifetime());
Ejemplo n.º 31
0
 public abstract void Config(IDependencyRegistrator container, DependencyScope scope = DefaultDependencyScope);