Ejemplo n.º 1
0
        static void Main()
        {
            var root     = new ServiceContainer();
            var strategy = root.CreateStrategy <FruitInfo, FruitAttribute>(type => new FruitInfo(type));

            root.ScanExtensions(strategy);
            var cache = new ExtensionsCache <FruitInfo, IFruit>(root);

            foreach (var fruit in cache.GetAllExtensions())
            {
                Console.WriteLine(fruit.Name);
            }
        }
Ejemplo n.º 2
0
        public void AttrProps()
        {
            var root      = new ServiceContainer(true);
            var propValue = false;
            var strategy  =
                root
                .CreateStrategy <SimpleExtensionInfo, SimpleExtensionAttribute>(
                    (ctx, attr) =>
            {
                propValue = attr.Prop;
                return(new SimpleExtensionInfo(ctx.Type));
            });

            _extManager.ReflectionOnlyScanExtensions(
                new[] { Assembly.GetExecutingAssembly().FullName },
                strategy);
            Assert.IsTrue(propValue);
        }
Ejemplo n.º 3
0
        public void ExtensionCache()
        {
            var root     = new ServiceContainer(true);
            var strategy =
                root
                .CreateStrategy <SimpleExtensionInfo, SimpleExtensionAttribute>(
                    (ctx, attr) => new SimpleExtensionInfo(ctx.Type));

            _extManager.ReflectionOnlyScanExtensions(
                new[] { Assembly.GetExecutingAssembly().FullName },
                strategy);
            var cache = new ExtensionsCache <SimpleExtensionInfo, SimpleExtension>(root);
            var exts  = cache.GetAllExtensions();

            Assert.IsNotNull(exts);
            Assert.AreEqual(1, exts.Length);
            Assert.IsNotNull(exts[0]);
        }