public static IUnityContainer InitContainer() { var container = new UnityContainer(); container.RegisterDatabase<SampleDbContext>(dehydrate: true) .RegisterRepositories(); //container.RegisterDatabase<SampleDbContext>(dehydrate: true) // .RegisterRepository(x => x.Packages) // .RegisterRepository(x => x.PackagesConfig); return container; }
public void Test() { var container = new UnityContainer(); container.RegisterDatabase<MockDbContext>() .RegisterRepository(x => x.MockEntity1s) .RegisterRepository(x => x.MockEntity2s); var resolve1 = container.CreateChildContainer().Resolve<ResolveTree>(); Assert.AreSame(resolve1.DbContext, resolve1.Repo1.DbContext); Assert.AreSame(resolve1.DbContext, resolve1.Repo2.DbContext); var resolve2 = container.CreateChildContainer().Resolve<ResolveTree>(); Assert.AreNotSame(resolve1.DbContext, resolve2.DbContext); }