### Simple Decorator Equivalent Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Demonstrates an equivalent configuration to the decorator-by-type example, showing the underlying mechanism. ```csharp ObjectFactory.Configure(cfg => { cfg.For().Use(); cfg.For().Add(); }); ``` -------------------------------- ### Call Startable Start Method Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/using-the-container-model.md Find all registered instances implementing IStartable, create them, and call their Start() method. ```csharp container.Model.AllPossible().Select(x => container.GetInstance(x)).Cast().ToList().ForEach(x => x.Start()); ``` -------------------------------- ### Define Container Configuration with Registry Class Source: https://context7.com/structuremap/structuremap/llms.txt Shows how to organize StructureMap configurations using the `Registry` class. Registries can be subclassed and composed, allowing for modular and maintainable container setup. Includes examples of default, named, and singleton registrations. ```csharp using StructureMap; using StructureMap.Configuration.DSL; public class DataRegistry : Registry { public DataRegistry() { For().Use(); For().Use().Singleton(); // Named instances For().Add().Named("primary"); For().Add().Named("readonly"); For().Use("primary"); // set the default by name } } public class ApplicationRegistry : Registry { public ApplicationRegistry() { For().Use(); // Include another registry IncludeRegistry(); } } // Bootstrap the container var container = new Container(new ApplicationRegistry()); var service = container.GetInstance(); var db = container.GetInstance("readonly"); // resolve named instance ``` -------------------------------- ### Include Registries in Container Setup Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/registry-dsl.md Direct the `Container` to use the configuration defined in your custom `Registry` class during setup. ```csharp var container = new Container(cfg => { cfg.AddRegistry(); }); ``` -------------------------------- ### Using RepositoryInstance Directly Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md Example of directly using the custom RepositoryInstance for a few document types. ```csharp For>().Use>(); For>().Use>(); ``` -------------------------------- ### Container Initialization Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Shows how to initialize a StructureMap container with a specific registry. This is a fundamental step before resolving any dependencies. ```csharp var container = new Container(new FoobarRegistry()); ``` -------------------------------- ### Install StructureMap via NuGet Source: https://github.com/structuremap/structuremap/blob/master/documentation/get-structuremap.md Use this command to install the main StructureMap package from NuGet. This is the recommended way to add StructureMap to your project. ```powershell PM> Install-Package StructureMap ``` -------------------------------- ### Example Classes with Connection String Constructor Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/policies.md Illustrates legacy classes that require a 'connectionString' constructor argument, demonstrating a scenario where a policy can simplify configuration. ```csharp public class DatabaseUser { public DatabaseUser(string connectionString) { } } public class User { public User(string connectionString) { } } ``` -------------------------------- ### GetInstance by Name Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/get-a-service-by-plugin-type-and-name.md Demonstrates how to get a specific service instance by its plugin type and a given name. ```APIDOC ## Get a Service by Plugin Type and Name ### Description This section details how to retrieve a specific service instance when multiple configurations exist for the same plugin type. You can request a named configuration for a given PluginType by using the overloads of `IContainer.GetInstance()` that take in a name. ### Method `IContainer.GetInstance(Type pluginType, string name)` ### Parameters #### Path Parameters - **pluginType** (Type) - Required - The type of the plugin service to retrieve. - **name** (string) - Required - The specific name of the service configuration to retrieve. ### Request Example ```csharp // Assuming 'container' is an instance of IContainer var serviceInstance = container.GetInstance("MyNamedService"); ``` ### Response #### Success Response (200) - **serviceInstance** (IMyService) - An instance of the requested service matching the specified name. #### Response Example (Example response depends on the actual service implementation and configuration) ``` -------------------------------- ### Install StructureMap via NuGet Source: https://github.com/structuremap/structuremap/blob/master/README.markdown Use this command to install the StructureMap package using the Package Manager Console. ```powershell Install-Package StructureMap ``` -------------------------------- ### Basic Dependency Injection Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/concepts.md Demonstrates how to use Dependency Injection to provide dependencies to an object. This approach decouples the object from the creation of its dependencies. ```csharp public class MyService : IMyService { private readonly IDependency _dependency; // Constructor injection public MyService(IDependency dependency) { _dependency = dependency; } public void DoSomething() { _dependency.DoSomethingElse(); } } ``` -------------------------------- ### PluginFamily Configuration Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Illustrates how StructureMap internally manages a PluginFamily, which represents a plugin type and all its possible plugged types. This example shows `IFoo` with two potential implementations, `Foo` and `SomeOtherFoo`, where `Foo` is the default. ```csharp public class PluginFamilyRegistry : Registry { public PluginFamilyRegistry() { For().Use(); For().Use().Named("secondary"); } } ``` -------------------------------- ### Activateable Widget Implementation Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md An example implementation of the `Activateable` interface for a `Widget` class. ```csharp public class AWidget : Activateable { public bool Activated { get; set; } public void Activate() { Activated = true; } } ``` -------------------------------- ### Create a Simple Registry Class Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/registry-dsl.md Subclass the `Registry` class and use its fluent interface methods to configure the container. This example configures an instance of an `IWidget` interface. ```csharp public class WidgetRegistry : Registry { public WidgetRegistry() { For().Use(); } } ``` -------------------------------- ### Define an Interface for a Dummy Service Source: https://github.com/structuremap/structuremap/blob/master/documentation/autofactory.md This is an example interface for a dummy service that will be used with auto-factories. ```csharp public interface IDummyService { void DoSomething(); } ``` -------------------------------- ### StructureMap Configuration Exception Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/validating-container-configuration.md This is an example of the exception StructureMap throws when configuration validation fails. It summarizes all build/configuration failures and validation errors encountered. ```text StructureMap.StructureMapConfigurationException StructureMap Failures: 1 Build/Configuration Failures and 0 Validation Errors Profile 'DEFAULT' ----------------------------------------------------------------------------------------------------- Build Error on Instance 'StructureMap.Testing.Diagnostics.NamedWidget' for PluginType StructureMap.Testing.Diagnostics.IWidget Unable to create a build plan for concrete type StructureMap.Testing.Diagnostics.NamedWidget new NamedWidget(String name) ┗ String name = Required primitive dependency is not explicitly defined ``` -------------------------------- ### Singleton Attribute Usage Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/attributes.md Demonstrates the usage of the [Singleton] attribute on concrete types to enforce singleton lifecycle. ```csharp public class SingletonRegistry : Registry { public SingletonRegistry() { Scan(x => { x.TheCallingAssembly(); x.WithDefaultConventions(); x.LookForAttributes(); }); } } [Singleton] public class SingletonWidget : Widget { } [Singleton] public class SingletonColor : Color { } ``` -------------------------------- ### Try Get Instance by Plugin Type and Name Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/try-geting-an-optional-service-by-plugin-type-and-name.md Use `IContainer.TryGetInstance(name)` or `IContainer.TryGetInstance(Type pluginType, string name)` to get a service by its type and name. This method returns null if the service is not found, preventing exceptions. ```csharp var instance = container.TryGetInstance("MySpecificService"); if (instance != null) { // Use the instance } ``` ```csharp var pluginType = typeof(IMyService); var instance = container.TryGetInstance(pluginType, "MySpecificService"); if (instance != null) { // Use the instance } ``` -------------------------------- ### Define Objects for Missing Instance Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/handling-missing-named-instances.md Define the interface and concrete implementation classes used in the missing named instance examples. ```csharp public interface IRule { string Color { get; } } ``` ```csharp public class ColorRule : IRule { public ColorRule(string color) { Color = color; } public string Color { get; } } ``` -------------------------------- ### AppSetting Attribute Target Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/attributes.md Example of a concrete type decorated with the custom [AppSetting] attribute to inject values from AppSettings into its constructor and properties. ```csharp public class AppSettingTarget { public string Name { get; set; } public AppSettingTarget([AppSetting("name")] string name) { Name = name; } } ``` -------------------------------- ### Install StructureMap via NuGet or .NET CLI Source: https://context7.com/structuremap/structuremap/llms.txt Use these commands to add the StructureMap package to your .NET project. ```powershell # NuGet Package Manager Install-Package StructureMap ``` ```powershell # .NET Core CLI dotnet add package structuremap ``` -------------------------------- ### Basic Service Location Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/concepts.md Illustrates how to use StructureMap's Container to resolve services on demand. This is an alternative to Dependency Injection, often used for more advanced scenarios. ```csharp public class AnotherService { public void DoSomething() { // Service locator usage var dependency = ObjectFactory.GetInstance(); dependency.DoSomethingElse(); } } ``` -------------------------------- ### Register Named Instances with Shorthand Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/registry-dsl.md A shorthand syntax for registering named instances. This achieves the same result as the previous example, registering a `Widget` implementation named 'primary'. ```csharp For().Add GetNames(); } ``` -------------------------------- ### Auto Wiring Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Demonstrates StructureMap's auto-wiring capabilities by inferring dependencies from constructor parameters. This reduces the need for explicit configuration for simple dependency injection. ```csharp public class AutoWiring { public AutoWiring(IWhatever whatever, ISomeDependency someDependency) { Whatever = whatever; SomeDependency = someDependency; } public IWhatever Whatever { get; } public ISomeDependency SomeDependency { get; } } ``` -------------------------------- ### Database User Constructor Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/policies.md Illustrates constructor signatures for classes that depend on IDatabase. These constructors show how the parameter names ('red', 'green') are used to specify which named IDatabase service should be injected. ```csharp public class DatabaseUser { private readonly IDatabase _database; public DatabaseUser(IDatabase red) { _database = red; } } public class AnotherUser { private readonly IDatabase _database; public AnotherUser(IDatabase green) { _database = green; } } ``` -------------------------------- ### ContainerScoped Lifecycle Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/object-lifecycle/supported-lifecycles.md Demonstrates the 'ContainerScoped' lifecycle, introduced in StructureMap 4.0. A new instance is built once per 'Container', meaning the root, child, profile, and nested containers each get their own instance. ```csharp public class ContainerScopedTester { [Fact] public void ContainerScopedInAction() { // Container.Configure(x => x.For().ContainerScoped()); // var container = Container.For(); // var root = container.GetInstance(); // var nested = container.GetNestedContainer().GetInstance(); // Assert.NotEqual(root.GetHashCode(), nested.GetHashCode()); } } ``` -------------------------------- ### Example of Type Scanning Configuration Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/type-scanning.md This snippet demonstrates setting up a StructureMap Container with multiple scanning operations using registries. It serves as a precursor to inspecting what was scanned. ```csharp var container = new Container(_ => { _.Scan(x => { x.TheCallingAssembly(); x.WithDefaultConventions(); }); _.Scan(x => { x.AssembliesFromPath("plugins", Assembly.Load); x.LookForRegistries(); }); }); ``` -------------------------------- ### Nested Container Disposal Example Classes Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/nested-containers.md Defines the simple IDisposable classes used in the nested container disposal example. ```csharp public class Color : IDisposable { public void Dispose() { // Cleanup logic here } } public class Blue : Color { } public class Red : Color { } ``` -------------------------------- ### Implement ILogVisualizer with StructureMap Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md This example shows how to implement the `ILogVisualizer` interface using StructureMap's generic type resolution capabilities. It demonstrates finding the appropriate `IVisualizer` for a given log object. ```csharp public class LogVisualizer : ILogVisualizer { public string ToHtml(object log) { // This is a bit of a hack, but it works. StructureMap can figure out // the correct IVisualizer to use by looking at the concrete type of the 'log' object return Container.ForObject(log).GetRequiredService().ToHtml(); } } ``` -------------------------------- ### Install StructureMap via .NET Core CLI Source: https://github.com/structuremap/structuremap/blob/master/README.markdown Use this command to add the StructureMap package to your .NET Core project. ```bash dotnet add package structuremap ``` -------------------------------- ### Decorator by Type Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Configures StructureMap to decorate all instances of IWidget with the WidgetHolder decorator. ```csharp ObjectFactory.Configure(cfg => { cfg.For().DecorateAllWith(); }); ``` -------------------------------- ### FuncInterceptor by Expression and IContext Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Configures a decorator using FuncInterceptor with an Expression that includes IContext, allowing context-aware decorator creation. ```csharp ObjectFactory.Configure(cfg => { cfg.For().InterceptWith>((ctx, svc) => { // Create or wrap the service instance here using ctx return svc => new MyServiceDecorator(svc, ctx.GetInstance()); }, "My custom decorator with context"); }); ``` -------------------------------- ### Usage Example: Injecting Named Databases Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/policies.md Demonstrates the runtime usage of StructureMap with the InjectDatabaseByNamePolicy. This code shows how to configure the container with the policy and named databases, and then retrieve instances of DatabaseUser and AnotherUser to verify that the correct database implementations are injected. ```csharp var container = new Container(x => { x.Policies.Add(new InjectDatabaseByNamePolicy()); x.For().Add().Named("red"); x.For().Add().Named("green"); x.Scan(s => { s.AssemblyContainingType(); s.ConnectImplementationsToTypesClosing(typeof(IDatabase)); }); }); var user = container.GetInstance(); var another = container.GetInstance(); // Assertions would go here to check that user._database is the 'red' instance // and another._database is the 'green' instance. ``` -------------------------------- ### Registering ISession with a Lambda Func (with context, with description) Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/lambdas.md This example shows registering an ISession using a Func lambda that requires the IContext, including a descriptive string for diagnostics. ```csharp For().Use(x => x.ConstructedBy("NHibernate Session", ctx => ctx.GetInstance().OpenSession())); ``` -------------------------------- ### PluginType and PluggedType Resolution Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Demonstrates the relationship between plugin type and plugged type. When `IFoo` is requested, an instance of `Foo` is returned, fulfilling the contract. ```csharp var foo = container.GetInstance(); // Returns an instance of Foo ``` -------------------------------- ### Registering ISession with a Lambda Expression (with context) Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/lambdas.md This example shows registering an ISession using a lambda expression that utilizes the IContext to construct the object. ```csharp For().Use(x => x.ConstructedBy(ctx => new NHibernateFactory().CreateSession(ctx.GetInstance())); ``` -------------------------------- ### Get a Named Service Instance Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/get-a-service-by-plugin-type-and-name.md Use the GetInstance() overload that accepts a name to retrieve a specific configuration of a plugin type. ```csharp var service = container.GetInstance("MyPluginName"); ``` -------------------------------- ### Get All Instances of a Plugin Type Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/get-all-services-by-plugin-type.md Use `GetAllInstances()` to retrieve all configured objects for a specific PluginType. This method respects the order in which instances are configured in the Container. ```csharp var allWidgets = container.GetAllInstances(); ``` -------------------------------- ### Using StructureMap Container with Type Scanning Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md This example shows how to create a StructureMap `Container` using the `VisualizationRegistry`. The container will then automatically resolve generic implementations based on the type scanning configuration. ```csharp var container = new Container(new VisualizationRegistry()); var issueCreatedVisualizer = container.GetInstance>(); var issueResolvedVisualizer = container.GetInstance>(); var defaultLogVisualizer = container.GetInstance>(); Assert.IsInstanceOf(issueCreatedVisualizer); Assert.IsInstanceOf(issueResolvedVisualizer); Assert.IsInstanceOf>(defaultLogVisualizer); ``` -------------------------------- ### Multi-Tenancy Data Lookup Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/handling-missing-named-instances.md Illustrates using the missing named instance feature to perform data lookups within StructureMap for constructing client-specific rules. This allows dynamic rule generation based on external data. ```csharp public class RuleLookupService { private readonly IContainer _container; public RuleLookupService(IContainer container) { _container = container; } public IRule GetRuleForClient(string clientId) { // StructureMap will try to find a rule named 'clientId'. // If not found, it will use the missing named instance policy to create one. return _container.GetInstance(clientId); } } // Assume RuleLookupService is configured elsewhere // Example of the missing named instance policy configuration: // registry.Policies.MissingNamedInstance(instance => // { // instance.TheDefault.Is.ConstructedBy(name => // { // // Simulate looking up rule configuration for 'name' (clientId) // var ruleConfig = LoadRuleConfiguration(name); // return new ClientRule(name) { /* ... use ruleConfig ... */ }; // }); // }); ``` -------------------------------- ### Configure Container Using Registry Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/index.md Configure a StructureMap Container by directing it to use the configuration defined in a Registry class. This simplifies the container setup process. ```csharp var container = new Container(new AppRegistry()); ``` -------------------------------- ### Define IStartable Interface Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/using-the-container-model.md Defines an interface for objects that need to be started after container bootstrapping. ```csharp public interface IStartable { void Start(); } ``` -------------------------------- ### FuncInterceptor by Expression Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Configures a decorator using a FuncInterceptor with a .NET Expression for runtime AOP or custom decorator object creation. ```csharp ObjectFactory.Configure(cfg => { cfg.For().InterceptWith>(x => { // Create or wrap the service instance here return svc => new MyServiceDecorator(svc); }, "My custom decorator"); }); ``` -------------------------------- ### Stubs with Child Containers Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/profiles-and-child-containers.md Example of using child containers to isolate stubbed services in automated integration tests. ```csharp public class IntegrationTest { [Fact] public void TestSomething() { var container = new Container(cfg => { cfg.For().Use(); cfg.For().Use(); }); // ... setup test data and execute code under test ... var authService = container.GetInstance(); var emailService = container.GetInstance(); // ... assert against stubbed services ... } } ``` -------------------------------- ### Registering ISession with a Lambda Func (no context, with description) Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/lambdas.md This example demonstrates registering an ISession using a Func lambda that does not require the IContext, including a descriptive string for diagnostics. ```csharp For().Use(x => x.ConstructedBy("NHibernate Session", () => new NHibernateFactory().CreateSession())); ``` -------------------------------- ### Custom Constructor Rule Implementation Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/constructor-selection.md Provides an example of a custom IConstructorSelector implementation to override default constructor behavior for specific types. ```csharp public class CustomCtorRule : IConstructorSelector { public ConstructorInfo SelectConstructor(Type serviceType, Instance instance) { return serviceType.GetConstructors().OrderByDescending(x => x.GetParameters().Length).First(); } } ``` -------------------------------- ### ThreadLocal Lifecycle Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/object-lifecycle/supported-lifecycles.md Illustrates the ThreadLocal lifecycle, where only one object instance is created for the currently executing thread. This is a seldom-used lifecycle. ```csharp public class ThreadLocalStorageTester { [Fact] public void ThreadLocalStorage() { // Container.Configure(x => x.For().ThreadLocal()); // var container = Container.For(); // var instance1 = container.GetInstance(); // var instance2 = default(IThreadLocal); // var thread = new Thread(() => { instance2 = container.GetInstance(); }); // thread.Start(); // thread.Join(); // Assert.Equal(instance1.GetHashCode(), instance2.GetHashCode()); } } ``` -------------------------------- ### Registering ISession with a Lambda Factory (with description) Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/lambdas.md This example shows how to register an NHibernate ISession using a lambda function that includes a descriptive string for diagnostic purposes. ```csharp For().Use(x => x.ConstructedBy("NHibernate Session", new NHibernateFactory())); ``` -------------------------------- ### Explicit Enumeration Behavior Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/working-with-enumerable-types.md This example shows how to override the default enumerable behavior by providing explicit configuration for how enumerable types should be handled. ```csharp public class explicit_enumeration_behavior { [Fact] // or [Test] public void Can_override_the_default_behavior_with_explicit_configuration() { var container = new Container(x => { x.For().Use(); x.For().Use(); x.For().Use(); // Explicitly configure how to build an array of IWidget x.For().Use(new IWidget[] { new C(), new B() }); }); var widgets = container.GetAllInstances(); Assert.Equal(3, widgets.Count()); Assert.IsType(widgets.First()); Assert.IsType(widgets.Skip(1).First()); Assert.IsType(widgets.Skip(2).First()); } public interface IWidget {} public class A : IWidget {} public class B : IWidget {} public class C : IWidget {} } ``` -------------------------------- ### Get Instance by PluginType Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/get-a-service-by-plugintype.md Use IContainer.GetInstance() to retrieve the default configured object for a specific plugin type. Ensure the plugin type is correctly registered in the container. ```csharp var instance = container.GetInstance(); ``` -------------------------------- ### AlwaysUnique Lifecycle Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/object-lifecycle/supported-lifecycles.md Demonstrates the 'AlwaysUnique' lifecycle, where a new object instance is created every time it's requested. These instances are not tracked or disposed by StructureMap. ```csharp public class AlwaysUniqueTester { [Fact] public void HowAlwaysUniqueWorks() { // Container.Configure(x => x.For().AlwaysUnique()); // var container = Container.For(); // var instance1 = container.GetInstance(); // var instance2 = container.GetInstance(); // Assert.NotEqual(instance1.GetHashCode(), instance2.GetHashCode()); } } ``` -------------------------------- ### Install Strong Named StructureMap via NuGet Source: https://github.com/structuremap/structuremap/blob/master/documentation/get-structuremap.md If you require a strong-named version of StructureMap, use this command. The StructureMap team advises against strong naming due to potential .Net land issues. ```powershell PM> Install-Package structuremap-signed ``` -------------------------------- ### Registering Plugin Type and Plugged Type Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Example of registering a concrete type for a given interface. Here, `Foo` is the plugged type that will be provided when an instance of `IFoo` (the plugin type) is requested. ```csharp public class FooRegistry : Registry { public FooRegistry() { For().Use(); } } ``` -------------------------------- ### Describe Build Plan for Default Instance Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/build-plans.md Retrieve the build plan for the default instance of a plugin type. This shows the detailed construction process, including decorators and dependency resolution. ```csharp var plan = container.Model.DescribeBuildPlan(); ``` -------------------------------- ### Custom Convention: Register Concrete Type Against Interfaces Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/auto-registration-and-conventions.md Provides an example of a custom IRegistrationConvention that registers a concrete type against all interfaces it implements. This customizes the auto-registration behavior. ```csharp public class RegisterConcreteTypeAgainstAllInterfacesConvention : IRegistrationConvention { public void Process(Type type, Registry registry) { if (type.IsConcrete()) { foreach (var @interface in type.GetInterfaces()) { registry.For(@interface).Use(type); } } } } ``` -------------------------------- ### Registering Multiple IDatabase Services Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/policies.md Registers two IDatabase services, 'red' and 'green', with StructureMap. This setup is used in conjunction with the InjectDatabaseByNamePolicy to demonstrate injecting specific database implementations based on parameter names. ```csharp x.For().Add().Named("red"); x.For().Add().Named("green"); ``` -------------------------------- ### Profile in Action Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/profiles-and-child-containers.md Illustrates how to configure and use a profile to manage service registrations. ```csharp var container = new Container(cfg => { cfg.Profile("Test", pcfg => { pcfg.For().Use(); }); }); var messageQueue = container.GetInstance(); Assert.IsType(messageQueue); container.RunProfile("Test", () => { var testMessageQueue = container.GetInstance(); Assert.IsType(testMessageQueue); }); ``` -------------------------------- ### Registering ISession with a Lambda Factory Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/lambdas.md This example demonstrates how to register an NHibernate ISession using a lambda function, allowing StructureMap to manage its lifecycle and creation via an ISessionFactory. ```csharp For().Use(x => x.ConstructedBy(new NHibernateFactory())); ``` -------------------------------- ### Run Documentation Website Locally Source: https://github.com/structuremap/structuremap/blob/master/README.markdown Commands to run the documentation website locally using Rake or the .NET CLI. ```bash rake docs ``` ```bash dotnet restore && dotnet stdocs run ``` -------------------------------- ### Register Named Instances Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/registry-dsl.md Register named instances when you have multiple implementations of an interface and need to retrieve a specific one. This example registers a `Widget` implementation named 'primary'. ```csharp For().Use().Named("primary"); ``` -------------------------------- ### Build and Test StructureMap with .NET CLI Source: https://github.com/structuremap/structuremap/blob/master/README.markdown Commands to clone the repository, run tests, and open the solution for development using the .NET CLI. ```bash git clone git://github.com/structuremap/structuremap.git ``` ```bash dotnet test src/StructureMap.Testing ``` -------------------------------- ### Anti-pattern: Explicit Dependency Fetching Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/auto-wiring.md Avoid tightly coupling your classes to the IoC container by explicitly fetching dependencies. This example shows an anti-pattern where a presenter directly requests its dependencies from the container. ```csharp public class ShippingScreenPresenter { private readonly IRepository _repository; private readonly IShippingService _shippingService; public ShippingScreenPresenter() { _repository = ObjectFactory.GetInstance(); _shippingService = ObjectFactory.GetInstance(); } // ... other methods } ``` -------------------------------- ### StructureMap Exception for Undefined Primitive Dependency Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/primitives.md This example demonstrates the exception thrown when a concrete type with primitive dependencies is requested without those dependencies being explicitly defined. The build plan will indicate which primitive dependency is missing. ```text new GuyWithNoDefaultName(String name) ┗ String name = Required primitive dependency is not explicitly defined ``` -------------------------------- ### InterceptorPolicy in Action Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Example demonstrating the usage of `InterceptorPolicy` from StructureMap's acceptance tests. ```csharp x.For().Interceptor(new WidgetInterceptorPolicy()); ``` -------------------------------- ### WidgetHolder Decorator Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Defines a decorator type that wraps another IWidget instance. ```csharp public class WidgetHolder : IWidget { private readonly IWidget _inner; public WidgetHolder(IWidget inner) { _inner = inner; } public void DoSomething() { // Do something before or after the inner widget's action _inner.DoSomething(); // Do something else } } ``` -------------------------------- ### EnumerableFamilyPolicy Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/on-missing-family-policies.md Fills requests for collections like IList, ICollection, and T[] with all known registrations of type T. ```csharp public class EnumerableFamilyPolicy : IFamilyPolicy { public bool Matches(Type familyType) { return familyType.IsGenericType && familyType.GetGenericTypeDefinition() == typeof(IEnumerable<>); } public PluginFamily Build(Type familyType, IContainer container) { var elementType = familyType.GetGenericArguments()[0]; var family = PluginFamily.Empty(elementType); // Add logic here to find and add all registrations for elementType // For example, using container.Model.GetAllPossible() return family; } } ``` -------------------------------- ### Implement a Dummy Service Source: https://github.com/structuremap/structuremap/blob/master/documentation/autofactory.md This is a concrete implementation of the IDummyService interface. ```csharp public class DummyService : IDummyService { public void DoSomething() { // Implementation details } } ``` -------------------------------- ### Custom Constructor Scenario Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/constructor-selection.md Sets up a scenario involving an abstract class hierarchy to demonstrate custom constructor selection logic. ```csharp public abstract class BaseThing {} public class Thing1 : BaseThing { public Thing1(string name, int size) { } } public class Thing2 : BaseThing { public Thing2(string name) { } } ``` -------------------------------- ### Resolve Specific Log Visualizer Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md Example of using StructureMap to resolve a specific visualizer for a known log type, such as IssueCreated. ```csharp container.GetInstance().ToHtml(new IssueCreated()); ``` -------------------------------- ### Modular Application with Fallback Registrations Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/fallback-services.md In application usage, add default `UseIfNone()` registrations and optionally include additional extension `Registry` objects from other assemblies. ```csharp public class MainAppRegistry : Registry { public MainAppRegistry() { IncludeRegistry(); IncludeRegistry(); IncludeRegistry(); } } ``` -------------------------------- ### LoggerFactory Sample Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/working-with-the-icontext-at-build-time.md This sample demonstrates a common pattern for creating loggers based on concrete types, often using static classes. ```csharp public class LoggerFactory { public static Logger For(Type type) { return new Logger(type); } } ``` -------------------------------- ### Basic Container Registration with Default Lifecycle Source: https://github.com/structuremap/structuremap/blob/master/documentation/glossary.md Demonstrates registering two interfaces with concrete types using StructureMap's Registry DSL. By default, both registrations will use the Transient lifecycle, creating a new instance for each request. ```csharp public class FoobarRegistry : Registry { public FoobarRegistry() { For().Use(); For().Use(); } } ``` -------------------------------- ### Define Role Interfaces Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/forwarding-requests-for-a-type-to-another-type.md Define interfaces for different roles that a class might fulfill. This example shows IReader and IWriter interfaces. ```csharp public interface IReader { object Get(string key); } public interface IWriter { void Add(string key, object data); } ``` -------------------------------- ### Programmatic Configuration of ConstructorInstance Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/inline-dependencies.md Build up ConstructorInstance objects directly to represent rules, bypassing the Registry DSL. This approach is useful for more complex or programmatic configuration scenarios. ```csharp var ruleInstance = new ConstructorInstance(typeof(SimpleRule)); ruleInstance.Inner.Set(new IsGreen()); ruleInstance.Inner.Set(new SendEmail()); x.Register(ruleInstance); ``` -------------------------------- ### ActivatorInterceptor Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Use this to create an activator interceptor that acts on an object castable to type T. The lambda must be a .NET Expression. ```csharp ObjectFactory.Configure(cfg => { cfg.For().InterceptWith>((IMyService svc) => { // Do something with svc }); }); ``` -------------------------------- ### Implement Default Visualizer Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md A concrete implementation of a default visualizer strategy that can be used as a fallback for log types without specific visualizers. ```csharp public class DefaultVisualizer : IVisualizer { public string ToHtml(object logMessage) { return $"
Default rendering for {logMessage.GetType().Name}
"; } } ``` -------------------------------- ### Resolve Services with StructureMap Container Methods Source: https://context7.com/structuremap/structuremap/llms.txt Utilize `IContainer` methods like `GetInstance`, `GetAllInstances`, and `TryGetInstance` to retrieve registered services. `GetInstance()` retrieves the default instance, `GetInstance(name)` a named instance, `GetAllInstances()` all instances, and `TryGetInstance()` safely returns null if unregistered. ```csharp using StructureMap; var container = new Container(_ => { _.For().Use(); _.For().Add().Named("blue"); _.For().Add().Named("red"); }); // Default resolution var widget = container.GetInstance(); // DefaultWidget // Named resolution var blue = container.GetInstance("blue"); // BlueWidget var red = container.GetInstance("red"); // RedWidget // Resolve by System.Type (useful when type is only known at runtime) var widget2 = (IWidget)container.GetInstance(typeof(IWidget)); // Get all registered instances in registration order IList all = container.GetAllInstances(); // [DefaultWidget, BlueWidget, RedWidget] // Safe resolution — returns null instead of throwing if not configured var optional = container.TryGetInstance(); // null if not registered // Resolve a concrete type with no explicit registration (auto-wiring) var coordinator = container.GetInstance(); // built automatically ``` -------------------------------- ### Passing Arguments with Fluent Interface Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/passing-arguments-at-runtime.md Invoke explicit argument passing using a fluent interface starting with `IContainer.With()`. This is an alternative to using `ExplicitArgs` directly. ```csharp var container = new Container(x => { x.For().Use(); }); // Override the connection string at runtime using IContainer.With() var db = container.With(new ExplicitArgs().Set("connectionString", "Server=prod")).GetInstance(); Assert.Equal("Server=prod", db.ConnectionString); ``` -------------------------------- ### Build Plan Visualization Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/auto-wiring.md This output visualizes how StructureMap resolves dependencies for a class using auto-wiring, showing the concrete types and lifecycles it selects. ```text PluginType: StructureMap.Testing.DocumentationExamples.ShippingScreenPresenter Lifecycle: Transient new ShippingScreenPresenter(IShippingService, IRepository) ┣ IShippingService = **Default** ┃ | PluginType: StructureMap.Testing.DocumentationExamples.IShippingService ┃ | Lifecycle: Transient ┃ | new InternalShippingService() ┃ ┗ IRepository = **Default** | PluginType: StructureMap.Testing.DocumentationExamples.IRepository | Lifecycle: Transient | new SimpleRepository() ``` -------------------------------- ### Explicit StructureMap Container Configuration Source: https://github.com/structuremap/structuremap/blob/master/documentation/quickstart.md Demonstrates how to explicitly configure a StructureMap Container to build instances of 'Foo' and 'Bar'. Use this when you need precise control over registrations. ```csharp var container = new Container(config => { config.For().Use(); config.For().Use(); }); var bar = container.GetInstance(); ``` -------------------------------- ### Describe Build Plan for Named Instance Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/build-plans.md Retrieve the build plan for a specific named instance of a plugin type. This is useful for understanding how StructureMap constructs particular configurations. ```csharp var plan = container.Model.DescribeBuildPlan("MyNamedDevice"); ``` -------------------------------- ### Define Default Fallback Registrations Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/fallback-services.md Use `UseIfNone()` to define default service registrations. This allows applications to override these defaults if needed. ```csharp public class ApplicationRegistry : Registry { public ApplicationRegistry() { // Default registrations that can be overridden For().UseIfNone(); For().UseIfNone(); } } ``` -------------------------------- ### Implementing IRegistrationConvention Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/auto-registration-and-conventions.md Shows the basic structure for creating a custom registration convention by implementing the IRegistrationConvention interface. This allows for custom auto-registration logic. ```csharp public class ConventionScanner : IRegistrationConvention { public void Process(Type type, Registry registry) { // ... logic to register the type } } ``` -------------------------------- ### ActivatorInterceptor with IContext Example Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Create an activator interceptor that acts on an object castable to type T, also utilizing the IContext service. The lambda must be a .NET Expression. ```csharp ObjectFactory.Configure(cfg => { cfg.For().InterceptWith>((ctx, svc) => { // Do something with svc using ctx }); }); ``` -------------------------------- ### Add Multiple Instances with For().AddInstances() Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/registry-dsl.md Quickly add several `Instances` to a single plugin type using the `AddInstances()` syntax. This is useful for registering multiple implementations concisely. ```csharp For().AddInstances(x => { x.Type(); x.Type(); }); ``` -------------------------------- ### Creating Nested Containers from Profiles Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/nested-containers.md Shows how to create a nested container based on a specific profile. This allows for modular configuration management. ```csharp var container = new Container(x => { x.Profile("Profile1", p => { p.For().Use(); }); }); // Create a nested container from the "Profile1" profile var nestedContainer = container.GetNestedContainer("Profile1"); // nestedContainer now has the IWidget registration from "Profile1" ``` -------------------------------- ### Generic Registrations with Fallback Source: https://github.com/structuremap/structuremap/blob/master/documentation/generics.md Demonstrates registering specific handlers for some generic types while allowing a fallback registration for others. This allows for special handling of certain types and a default strategy for the rest. ```csharp x.For(typeof(IVisualizer<>)).DecorateAllWith(typeof(DefaultVisualizer<>)); ``` -------------------------------- ### Supplying Primitive Dependency Explicitly Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/primitives.md This sample shows how to explicitly supply a value for a primitive dependency when building a concrete type. This resolves the exception that occurs when the dependency is not defined. ```csharp x.For().Use().CtorDependency().Is("The Guy"); ``` -------------------------------- ### Analyze StructureMap Build Plans and Container Model Source: https://context7.com/structuremap/structuremap/llms.txt Access container.Model to programmatically inspect instances and their build plans. The DescribeBuildPlan() method provides a detailed view of how a specific type is constructed, including its dependencies and lifecycle. You can also query the model to check for default implementations or retrieve all registered instances of a given type. ```csharp using StructureMap; var container = new Container (_ => { _.For().Use(); _.For().Use().Singleton(); _.For().Add().Named("redis"); _.For().Add().Named("memory"); }); // Inspect build plan for a specific type var plan = container.Model.For().Default.DescribeBuildPlan(); Console.WriteLine(plan); // Output: // PluginType: MyApp.IService // Lifecycle: Transient // new AppService(IRepository) // └ IRepository = **Default** // | Lifecycle: Singleton // | new SqlRepository() // Query the model programmatically bool hasCache = container.Model.HasDefaultImplementationFor(); var allCaches = container.Model.For().Instances.Select(i => i.ReturnedType); ``` -------------------------------- ### Basic Assembly Scanning Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/auto-registration-and-conventions.md Demonstrates the fundamental usage of Registry.Scan() for assembly scanning operations. Each call to Registry.Scan() is atomic and independent of others. ```csharp Registry.Scan( assembly => assembly.TheCallingAssembly(), scan => { scan.With(new ConventionScanner()); } ); ``` -------------------------------- ### Setter Injection Policies Source: https://github.com/structuremap/structuremap/blob/master/documentation/setter-injection.md Enable setter injection by configuring policies during Container setup using Registry.Policies.SetAllProperties(). This method allows for criteria-based selection of setters to be filled as mandatory dependencies. ```csharp public class MyRegistry : Registry { public MyRegistry() { SetAllProperties(x => x.Fill("Provider")); } } ``` -------------------------------- ### Work with Single Instance Reference Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/using-the-container-model.md Manipulate an individual instance within the container model. ```csharp var instanceRef = container.Model.Instance("some name"); Console.WriteLine(instanceRef.Description); ``` -------------------------------- ### Show a Child Container in Action Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/profiles-and-child-containers.md Demonstrates the basic usage of a child container to override parent container registrations. ```csharp var parent = new Container(cfg => { cfg.For().Use(); }); var child = parent.GetChildContainer(); child.Configure(cfg => { cfg.For().Use(); }); var messageQueue = child.GetInstance(); Assert.IsType(messageQueue); ``` -------------------------------- ### IContainer.GetInstance() Source: https://github.com/structuremap/structuremap/blob/master/documentation/resolving/get-a-service-by-plugintype.md Retrieves the default configured object for a given plugin type. ```APIDOC ## GetInstance ### Description Retrieves the default configured object for a given plugin type. ### Method `IContainer.GetInstance(Type pluginType)` ### Parameters #### Path Parameters - **pluginType** (Type) - Required - The type of the plugin for which to retrieve the instance. ### Response #### Success Response (Instance) - Returns the default configured object of the specified plugin type. ### Request Example ```csharp var service = container.GetInstance(typeof(IMyPlugin)); ``` ### Response Example ```csharp // Assuming IMYPlugin is configured, this would return an instance of its configured implementation. ``` ``` -------------------------------- ### Activateable Marker Interface Source: https://github.com/structuremap/structuremap/blob/master/documentation/interception-and-decorators.md Define the `Activateable` interface with an `Activate()` method for objects that require startup state initialization. ```csharp public interface Activateable { void Activate(); } ``` -------------------------------- ### Configuring Lifecycles with Attributes in StructureMap Source: https://github.com/structuremap/structuremap/blob/master/documentation/object-lifecycle/configuring-lifecycles.md Shows how to use attributes to configure lifecycles for plugin types or instances. Use the [Singleton] attribute for single instances or [AlwaysUnique] for always new instances. ```csharp // Mark a Plugin Type as Singleton [Singleton] public class MySingletonService : IMyService { } // Mark a Plugin Type as AlwaysUnique [AlwaysUnique] public class MyUniqueService : IMyService { } // Mark a specific Instance as Singleton For().Use().Singleton(); // Mark a specific Instance as AlwaysUnique For().Use().AlwaysUnique(); ``` -------------------------------- ### Opt-in to Scanning .exe Files Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/auto-registration-and-conventions.md Enables scanning of .exe files from the application's bin path by using a public method on AssemblyScanner. This is an opt-in feature due to potential issues. ```csharp Registry.Scan( assembly => assembly.AssembliesFromPath("bin", assembly => assembly.IsClass && !assembly.IsAbstract), scan => { scan.With(new ConventionScanner()); scan.IncludeNamespaceContainingType(); scan.ExcludeNamespace("SomeOtherNamespace"); } ); ``` -------------------------------- ### Inspect Type Scanning Operations Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/type-scanning.md Call `Container.WhatDidIScan()` to get a textual report of all type scanning operations, including assemblies scanned, their versions, and any assembly load failures. This is useful for understanding dynamic assembly loading. ```csharp Container.WhatDidIScan(); ``` -------------------------------- ### Registering an Existing Object Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/existing-objects.md Use `For().Use(object)` to register an existing object instance with the container. This makes the object a de facto singleton. ```csharp public class MyObject : IDisposable { public void DoSomething() { } public void Dispose() { } } // In your registry: For().Use(new MyObject()); ``` -------------------------------- ### Query All Instances for a Plugin Type Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/using-the-container-model.md Iterate over all registered instances for a specific plugin type. ```csharp var instances = container.Model.InstancesOf(); foreach (var instance in instances) { Console.WriteLine(instance.Description); } ``` -------------------------------- ### Using Default Parameter Arguments for Primitive Dependencies Source: https://github.com/structuremap/structuremap/blob/master/documentation/the-container/primitives.md Demonstrates how StructureMap can utilize default parameter arguments for primitive types, allowing for conventional derivation of values while still permitting explicit definition. ```csharp x.For().Use(); ``` -------------------------------- ### Registering SimpleRule with Constructor Injection Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/inline-dependencies.md Configure constructor parameters by type for a simple rule. This allows for different combinations of dependencies to be registered for the same type. ```csharp x.For().Use().Ctor().Is(); x.For().Use().Ctor().Is().Ctor().Is(); ``` -------------------------------- ### Convenience Base Class for Instance Policies Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/policies.md Use ConfiguredInstancePolicy as a base class for simpler policy creation, especially when dealing with inline dependencies like constructor arguments or setter properties. ```csharp public abstract class ConfiguredInstancePolicy : IInstancePolicy { public void Apply(Instance instance) { Configure(instance); } protected abstract void Configure(Instance instance); } ``` -------------------------------- ### Configure StructureMap Container at Runtime Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/changing-configuration-at-runtime.md Use the `IContainer.Configure()` method to add or change configuration on an existing StructureMap container object dynamically. This is generally recommended for testing scenarios on the root container. ```csharp var container = new Container(); container.Configure(x => { x.For().Use(); }); ``` -------------------------------- ### Configure StructureMap Container Source: https://github.com/structuremap/structuremap/blob/master/documentation/registration/index.md Configure a StructureMap Container using the fluent API to register services. Use For().Use() to register a default instance for a given plugin type, ensuring a new instance is created each time the abstraction is requested. ```csharp var container = new Container(x => { x.For().Use(); x.For().Use(); }); ``` -------------------------------- ### Create Container with Explicit Registrations Source: https://context7.com/structuremap/structuremap/llms.txt Demonstrates creating a StructureMap container by explicitly registering concrete types for interfaces. Dependencies are automatically resolved. Supports various registration methods including lambdas and pre-existing objects. ```csharp using StructureMap; public interface IRepository { IEnumerable GetAll(); } public interface IService { void Execute(); } public class SqlRepository : IRepository { public IEnumerable GetAll() => new[] { "item1", "item2" }; } public class AppService : IService { private readonly IRepository _repo; public AppService(IRepository repo) { _repo = repo; } public void Execute() { foreach (var item in _repo.GetAll()) Console.WriteLine(item); } } // Build the container with explicit registrations var container = new Container(_ => { _.For().Use(); // default _.For().Use(); // auto-wired: SqlRepository injected automatically // Alternative forms: _.For().Use(() => new SqlRepository()); // via lambda _.For().Use(new SqlRepository()); // pre-existing object _.For(typeof(IService<>)).Use(typeof(Service<>)); // open generic registration }); var service = container.GetInstance(); service.Execute(); ``` -------------------------------- ### Convention-Based StructureMap Configuration Source: https://github.com/structuremap/structuremap/blob/master/documentation/quickstart.md Shows how to configure a StructureMap Container using type scanning conventions. This approach simplifies configuration for common patterns. ```csharp var container = Container.For(); public class DefaultRegistry : Registry { public DefaultRegistry() { Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); }); } } var bar = container.GetInstance(); ``` -------------------------------- ### Test for Registrations Source: https://github.com/structuremap/structuremap/blob/master/documentation/diagnostics/using-the-container-model.md Check for the presence of expected configurations within the container model, useful for testing. ```csharp var hasRegistration = container.Model.HasType(); Console.WriteLine(hasRegistration); ```