Skip to content
Ian Johnson edited this page Mar 3, 2014 · 3 revisions

WhatDoIHave is an extension method for the IExportLocator inteface that generates configuration information as a string for the container or injection scope it's executed on.

Container example

Below is an example of configuring a container and then printing the output to the console

DependencyInjectionContainer container = new DependencyInjectionContainer();

container.Configure(c =>
			{
				c.Export<BasicService>().As<IBasicService>();
				c.Export<ConstructorImportService>().AndSingleton();
			});

string whatDoIHaveStr = container.WhatDoIHave(true);

Console.Write(whatDoIHaveStr);

Output

--------------------------------------------------------------------------------
Exports for scope 'RootScope' with id 4b6715f6-af32-4e1a-ba21-a96e299431d7
--------------------------------------------------------------------------------
Export Type: Grace.UnitTests.Classes.Simple.BasicService
Key: null
Environement: Any
Priority: 0
Externally Owned: False
Lifestyle: Transient
MeetsCondition: True
Depends On
	none

--------------------------------------------------------------------------------
Export Type: Grace.UnitTests.Classes.Simple.ConstructorImportService
Key: null
Environement: Any
Priority: 0
Externally Owned: False
Lifestyle: SingletonLifestyle
MeetsCondition: True
Depends On

	Dependency Type: ConstructorParameter
	Target Name: basicService
	Import Type: Grace.UnitTests.Classes.Simple.IBasicService
	Import Name: null
	Has Filter: False
	Has Value Provider: False

Child Scope Example

This example shows how to configure a child scope and then print out the child and parent content

DependencyInjectionContainer container = new DependencyInjectionContainer();

container.Configure(c => c.Export<ConstructorImportService>().AndSingleton());

using (IInjectionScope child = container.CreateChildScope(c => c.Export<BasicService>().As<IBasicService>()))
{
   string whatDoIHave = child.WhatDoIHave(true);

   Console.Write(whatDoIHave);
}

Produces output

--------------------------------------------------------------------------------
Exports for scope '' with id 87baebfd-5e93-4336-95dd-2811b84baf49
--------------------------------------------------------------------------------
Export Type: Grace.UnitTests.Classes.Simple.BasicService
Key: null
Environement: Any
Priority: 0
Externally Owned: False
Lifestyle: Transient
MeetsCondition: True
Depends On
	none

--------------------------------------------------------------------------------
Exports for scope 'RootScope' with id 2afb35f0-c3e6-47a8-b107-919417b9ae0f
--------------------------------------------------------------------------------
Export Type: Grace.UnitTests.Classes.Simple.ConstructorImportService
Key: null
Environement: Any
Priority: 0
Externally Owned: False
Lifestyle: SingletonLifestyle
MeetsCondition: True
Depends On

	Dependency Type: ConstructorParameter
	Target Name: basicService
	Import Type: Grace.UnitTests.Classes.Simple.IBasicService
	Import Name: null
	Has Filter: False
	Has Value Provider: False

Filter Example

Below is an example of configuring a container and a child scope, then printing out all the information on IBasicService exports

DependencyInjectionContainer container = new DependencyInjectionContainer();

container.Configure(c => c.Export<ConstructorImportService>().AndSingleton());

using (IInjectionScope child = container.CreateChildScope(c => c.Export<BasicService>().As<IBasicService>()))
{
   string whatDoIHave = child.WhatDoIHave(includeParent: true, 
                                          consider: ExportsThat.AreExportedAs<IBasicService>());

   Console.Write(whatDoIHave);
}

Produces output

--------------------------------------------------------------------------------
Exports for scope '' with id d6912a7c-9c5b-43f3-8dec-a717fae4eef4
--------------------------------------------------------------------------------
Export Type: Grace.UnitTests.Classes.Simple.BasicService
Key: null
Environement: Any
Priority: 0
Externally Owned: False
Lifestyle: Transient
MeetsCondition: True
Depends On
	none

--------------------------------------------------------------------------------
Exports for scope 'RootScope' with id 9cf50b14-eab3-4cde-a01e-b195d114d9be
Clone this wiki locally