コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public static Dictionary <Type, Type> FindContractToBuilderMatches()
        {
            var assembliesProvider = new CustomAssemblySourceProvider(PlatformProvider.Current.GetRootPath(),
                                                                      new[] { Consts.ContractsAssemblyEnding, Consts.BuildersAssemblyEnding });
            var assemblies               = assembliesProvider.Assemblies.ToArray();
            var contractTypes            = assemblies.FindContractTypes();
            var contractToBuilderMatches = FindContractToBuilderMatchesImpl(assemblies, contractTypes);

            return(contractToBuilderMatches);
        }
コード例 #3
0
        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);
        }