I just started using Cliburn Micro in my wpf application. I develop using dependency injection in order to help keep things abstract using interfaces.
How can I use the Caliburn Micros Bootstrappers Container to instantiate my own instances of classes.
For example
public interface IFoo
{
int ReturnNumber();
}
public class Foo : IFoo
{
public int ReturnNumber()
{
return 1;
}
}
public class SomeViewModel()
{
public SomeViewMode()
{
IFoo = //instance from caliburn
}
}
Within my bootstrapper I am using a CompositionContainer
----UPDATE------
I am Using Modern UI and Caliburn Micro frameworks side by side but get an null value exception in the bootstrapper at the GetInstance( Type, String ) method when the bootstrapper tried to resolve an instance for a type that contains a parameter for example IWindowManager. I believe this is due to the nature of ModernUI taking a View first approach using a content loader to communicate with Caliburn.Micro however I am struggling to find a solution that allows my bootstrapper to function properly.
Here is the configuration of the bootstrapper
public class AppBootstrapper : Bootstrapper<IShellViewModel>
{
private static CompositionContainer _container;
....
protected override void Configure()
{
// Add New ViewLocator Rule
ViewLocator.NameTransformer.AddRule(
@"(?<nsbefore>([A-Za-z_]\w*\.)*)?(?<nsvm>ViewModels\.)(?<nsafter>([A-Za-z_]\w*\.)*)(?<basename>[A-Za-z_]\w*)(?<suffix>ViewModel$)",
@"${nsbefore}Views.${nsafter}${basename}View",
@"(([A-Za-z_]\w*\.)*)?ViewModels\.([A-Za-z_]\w*\.)*[A-Za-z_]\w*ViewModel$"
);
_container = new CompositionContainer(
new AggregateCatalog(
new AssemblyCatalog( typeof( IShellViewModel ).Assembly ),
AssemblySource.Instance.Select( x => new AssemblyCatalog( x ) ).OfType<ComposablePartCatalog>().FirstOrDefault()
)
);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>( new WindowManager() );
batch.AddExportedValue<IEventAggregator>( new EventAggregator() );
_container.Compose( batch );
}
protected override object GetInstance( Type serviceType, string key )
{
string contract = string.IsNullOrEmpty( key ) ? AttributedModelServices.GetContractName( serviceType ) : key;
var exports = _container.GetExportedValues<object>( contract );
return exports.FirstOrDefault();
}
Am I missing something obvious?