Exemplo n.º 1
0
        public ContainerSettings RegisterSettings(object id)
        {
            ContainerSettings settings = new DefaultContainerSettings(id.ToString(), GetType().Name);

            string filename = Path.GetFileName(settings.GeneratedContainerAssemblyPath);
            if (null == filename) Assert.Fail("Could not get generated container assembly path filename.");
            settings.GeneratedContainerAssemblyPath =
                Path.Combine(_generatedFilesDirectory, filename);

            filename = Path.GetFileName(settings.GeneratedContainerSourceCodeFilename);
            if (null == filename) Assert.Fail("Could not get generated container source code filename.");
            settings.GeneratedContainerSourceCodeFilename =
                Path.Combine(_generatedFilesDirectory, filename);

            return settings;
        }
        public override void Prepare()
        {
            ContainerSettings settings = new DefaultContainerSettings("Speedioc");
            settings.ForceCompile = true;

            IRegistry registry = new Registry();

            registry.Register<Singleton>().As<ISingleton>().WithLifetime(Lifetime.Container).PreCreateInstance();
            registry.Register<Transient>().As<ITransient>().WithLifetime(Lifetime.Transient);
            registry.Register<Combined>().As<ICombined>().WithLifetime(Lifetime.Transient)
                .UsingConstructor()
                .WithResolvedParameter<ISingleton>()
                .WithResolvedParameter<ITransient>()
                .AsLastParameter();

            IContainerBuilder containerBuilder = DefaultContainerBuilderFactory.GetInstance(settings, registry);
            container = containerBuilder.Build();
        }
Exemplo n.º 3
0
        public void TestFixtureSetUp()
        {
            // Create a container.
            // There are two prerequisites for creating a container:
            // 1. Container settings
            // 2. One or more registries

            // Container Settings
            // Grab a new instance of the DefaultContainerSettings class specifying an identifier for the container.
            // A container identifier is an arbitrary string and it must follow the rules for assembly names (or identifiers).
            // Also, set the ForceCompile option to true. This is optional and it causes the container to be
            // regenerated and rebuilt each time it is initialized.
            // This may not be good for a production app, but it just depends on what you intend to accomplish.
            // For the scope of these lessons, turn the ForceCompile option on.
            ContainerSettings settings = new DefaultContainerSettings("SpeediocQuickStartLessons");
            settings.ForceCompile = true;

            // Registry
            // Please take the time now to look at the QuickStartRegistry class and read
            // through all of the comments (lessons) to learn how the registration API works.
            // It is likely that you will reference the registry class throughout the lessons.
            IRegistry registry = new QuickStartRegistry();

            // Get a container builder and bulid the container.
            IContainerBuilder containerBuilder = DefaultContainerBuilderFactory.GetInstance(settings, registry);
            Container = containerBuilder.Build();	// Set the new container to the Container property for use in other test methods.

            // Now that the container has been built, there are no more opportunities to register types.
            // Don't panic. :-)
            // As you read through the tests, which resolves instances from the container,
            // please reference the QuickStartRegistry class to observe the relationship between each
            // registration and the tests which request instances based on those registrations.
        }