public static Foo GetInstance(int parameter)
 {
     if (FooCache.IsCached(parameter))
     {
         // return instance from cache
     }
     else
     {
         Foo instance = new Foo(parameter);
         // add to cache
         return(instance);
     }
 }
Exemplo n.º 2
0
        public void Cache_Composability()
        {
            var fooCache = new FooCache();
            var s1       = "hello";
            var s2       = Copy(s1);
            var foo1     = new Foo {
                Bar = new Bar {
                    Baz = s1, Qux = new object()
                }, Num = 42
            };
            var foo2 = new Foo {
                Bar = new Bar {
                    Baz = s2, Qux = new object()
                }, Num = 42
            };

            Assert.AreNotSame(s1, s2);

            var ref1 = fooCache.Create(foo1);
            var ref2 = fooCache.Create(foo2);

            Assert.AreSame(ref1.Value.Bar.Baz, ref2.Value.Bar.Baz);
        }