Ejemplo n.º 1
0
 public AutofacGlassFactoryBuilder(IConfigurationOptions options, IContainer container,
                                   Func <ILookup <Type, GlassInterfaceMetadata>, IGlassTemplateCacheService> templateCacheFactory,
                                   IGlassTypesLoader typeLoader, IImplementationFactory implFactory)
     : base(options)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (templateCacheFactory == null)
     {
         throw new ArgumentNullException(nameof(templateCacheFactory));
     }
     if (typeLoader == null)
     {
         throw new ArgumentNullException(nameof(typeLoader));
     }
     if (implFactory == null)
     {
         throw new ArgumentNullException(nameof(implFactory));
     }
     _container            = container;
     _templateCacheFactory = templateCacheFactory;
     _typeLoader           = typeLoader;
     _implFactory          = implFactory;
 }
Ejemplo n.º 2
0
 public DebuggingDecorator(IImplementationFactory innerFactory, bool debuggingEnabled)
 {
     if (innerFactory == null)
     {
         throw new ArgumentNullException(nameof(innerFactory));
     }
     _innerFactory      = innerFactory;
     IsDebuggingEnabled = debuggingEnabled;
 }
        public override IGlassInterfaceFactory BuildFactory()
        {
            IImplementationFactory implFactory = null;

            var implementedTypes = new DefaultGlassTypeLoader().LoadImplementations(Options.Assemblies);
            var templateCache    = new GlassTemplateCacheService(implementedTypes, _serviceFactory);

            implFactory = new ProxyImplementationFactory((t, model) => new FallbackInterceptor(t, model, templateCache, implFactory));

            return(new GlassInterfaceFactory(templateCache, implFactory));
        }
Ejemplo n.º 4
0
        public void TestSetup()
        {
            _mockOptions = Substitute.For <IConfigurationOptions>();
            _mockOptions.Assemblies.Returns(new[] { Assembly.GetAssembly(GetType()).FullName });
            _mockContainer = Substitute.For <IContainer>();

            _mockImplFactory = Substitute.For <IImplementationFactory>();
            _mockCache       = Substitute.For <IGlassTemplateCacheService>();
            _mockTypeLoader  = Substitute.For <IGlassTypesLoader>();

            _builder = new AutofacGlassFactoryBuilder(_mockOptions, _mockContainer, lookup => _mockCache, _mockTypeLoader, _mockImplFactory);
        }
Ejemplo n.º 5
0
        public GlassInterfaceFactory(IGlassTemplateCacheService templateCache, IImplementationFactory factory)
        {
            if (templateCache == null)
            {
                throw new ArgumentNullException(nameof(templateCache));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            _templateCache = templateCache;
            _factory       = factory;
        }
Ejemplo n.º 6
0
 public FallbackInterceptor(Type interfaceType, object model, IGlassTemplateCacheService templateCache, IImplementationFactory implementationFactory)
 {
     if (interfaceType == null)
     {
         throw new ArgumentNullException(nameof(interfaceType));
     }
     if (model == null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     if (templateCache == null)
     {
         throw new ArgumentNullException(nameof(templateCache));
     }
     if (implementationFactory == null)
     {
         throw new ArgumentNullException(nameof(implementationFactory));
     }
     _interfaceType         = interfaceType;
     _model                 = model;
     _templateCache         = templateCache;
     _implementationFactory = implementationFactory;
 }
Ejemplo n.º 7
0
 public JsonUnmarshaller(IImplementationFactory factory)
 {
     this._factory = factory;
 }
Ejemplo n.º 8
0
 public ICallService GetUnmarshaller(IImplementationFactory implementationFactory)
 {
     return(_unmarshaller ?? (_unmarshaller = new JsonUnmarshaller(implementationFactory)));
 }
Ejemplo n.º 9
0
        public void Initialize()
        {
            _mockService = Substitute.For <ISitecoreService>();

            var typeDictionary = new Dictionary <Type, IEnumerable <GlassInterfaceMetadata> >
            {
                // Type of Glass Factory Interface (and associated 'abstract' implementations)
                {
                    typeof(ITestInterface), new[]
                    {
                        // Base Type, matches no direct template
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IBaseType),
                            ImplementationType = typeof(IBaseTypeModel),
                            IsFallback         = true,
                            ZIndex             = 0
                        },
                        // Actual sitecore template type, inherits BaseType
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IInheritedTemplate),
                            ImplementationType = typeof(IInheritedTemplateLowerPriorityModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        },
                        // Actual sitecore template type, inherits BaseType
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IInheritedTemplate),
                            ImplementationType = typeof(IInheritedTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 1
                        },
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IIntermediateTemplate),
                            ImplementationType = typeof(IIntermediateTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        }
                    }
                },
                {
                    typeof(INestedTestInterface), new[]
                    {
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IIntermediateTemplate),
                            ImplementationType = typeof(IIntermediateTemplateModel),
                            IsFallback         = false,
                            ZIndex             = 0
                        },
                        // Base Type, matches no direct template
                        new GlassInterfaceMetadata
                        {
                            GlassType          = typeof(IBaseType),
                            ImplementationType = typeof(IBaseTypeModel),
                            IsFallback         = true,
                            ZIndex             = 0
                        },
                    }
                }
            };

            _interfaceMappings = typeDictionary
                                 .SelectMany(pair => pair.Value,
                                             (pair, metadata) => new KeyValuePair <Type, GlassInterfaceMetadata>(pair.Key, metadata))
                                 .ToLookup(pair => pair.Key, pair => pair.Value);

            // Tightly-coupled test dependency... hmm
            _implFactory = new ProxyImplementationFactory((t, model) => new FallbackInterceptor(t, model, _glassFactory.TemplateCacheService, _implFactory));

            _templateCache = new GlassTemplateCacheService(_interfaceMappings, () => _mockService);

            // System Under Test
            _glassFactory = new GlassInterfaceFactory(_templateCache, _implFactory);
        }
Ejemplo n.º 10
0
        public RegistryKeyInitializerFactory()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            _implementationFactory = new ImplementationFactory(assembly);
        }