示例#1
0
        public void Scan_Scoped()
        {
            var provider = _dependencies
                           .Scan(scanner => scanner
                                 .AssemblyOf <IRepository>()
                                 .ScopedOf <IRepository>())
                           .BuildProvider();

            var repositories1 = provider.GetRequiredService <IRepository[]>();

            using (var scope = provider.CreateScope())
            {
                var repositories2 = scope.GetRequiredService <IRepository[]>();
                for (var i = 0; i < repositories1.Length; i++)
                {
                    Assert.NotEqual(repositories1[i], repositories2[i]);
                }
            }
        }