I have interface: IAutoMapperConfiguration which has 1 method "void
Configure()"
I have about 15 classes that implement only this interface, all are
public. And all they do in this method is make calls to
AutoMapper.CreateMap() and specify the parameters, etc.. to do the
mapping.
I came up with this idea based on a snippet I saw in storyTeller with
IStartable
So I have my scanner setup to do this:
Scan(x =>
{
x.TheCallingAssembly();
x.AddAllTypesOf<IAutoMapperConfiguration>();
x.WithDefaultConventions();
});
So it should find all my classes and add them to the container.
Then in my bootstrapper I am doing this:
List<IAutoMapperConfiguration> mappers = container.Model.PluginTypes
.Where(p => p.Implements<IAutoMapperConfiguration>())
.Select(x => x.To<IAutoMapperConfiguration>
(container)).ToList();
mappers.Each(x => x.Configure());
Problem is, SM never finds my IAuotMapperConfiguration classes. I have
tried several different scenarios, and AddAllTypesOf sounds like it
should work from the documentation. But I keep coming up empty handed.
Any ideas?
Create a class that takes in an array of IAutoMapperConfiguration in
its constructor. Give it a method (Configure) which loops over each
injected instance and calls Configure.
(pseudo code):
class AutoMapperConfigurer{
public AutoMapperConfigurer(IAutoMapperConfiguration mappers){
_mappers = mappers;
}
public void Configure(){
_mappers.Each(x => x.Configure());
}
}
Then in your bootstrapper, after you have initialized the container:
container.GetInstance<AutoMapperConfigurer>().Configure();
In your bootstrapper, you
> --
>
> You received this message because you are subscribed to the Google Groups "structuremap-users" group.
> To post to this group, send email to structure...@googlegroups.com.
> To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/structuremap-users?hl=en.
>
>
>
ForRequestedType<IAutoMapperConfiguration>()
.AddInstances(x =>
{
x.OfConcreteType<AdCreativeMapConfigs>().WithName("AdCreativeMaps");
x.OfConcreteType<AdManagerInvoiceMaps>().WithName("AdInvoiceMaps");
x.OfConcreteType<AdvertisementMapsConfiguration>().WithName
("AdvertisementMaps");
x.OfConcreteType<AnnouncementMaps>().WithName("AnnouncementMaps");
x.OfConcreteType<BlogMapConfigs>
().WithName("BlogMapConfigs");
x.OfConcreteType<CommentMapConfigs>().WithName("CommentMapConfigs");
x.OfConcreteType<DistricStandingMapConfiguration>().WithName
("DistricStandingMapConfiguration");
x.OfConcreteType<ForumMappingConfig>().WithName("ForumMappingConfig");
x.OfConcreteType<GameMapConfiguration>().WithName
("GameMapConfiguration");
x.OfConcreteType<GenericKeyValuePairMaps>().WithName
("GenericKeyValuePairMaps");
x.OfConcreteType<ImageMappingConfig>().WithName("ImageMappingConfig");
x.OfConcreteType<PodcastMapConfigs>().WithName("PodcastMapConfigs");
x.OfConcreteType<PlayerMappingConfig>().WithName
("PlayerMappingConfig");
x.OfConcreteType<RegionMapConfigs>().WithName("RegionMapConfigs");
x.OfConcreteType<SchoolMapConfiguration>().WithName
("SchoolMapConfiguration");
x.OfConcreteType<ScoreMapConfigurations>().WithName
("ScoreMapConfigurations");
x.OfConcreteType<SiteWideAnnouncementMaps>().WithName
("SiteWideAnnouncementMaps");
x.OfConcreteType<UserMapConfig>
().WithName("UserMapConfig");
x.OfConcreteType<AutoMapperConfiguration>();
});
This seemed to be the only way I could get SM to know about my
objects. Everything else in the assembly was scanned just fine though
As it stands now, anytime I want to make a new map configuration file
I will have to register it manually and that just sucks.
On Dec 22, 10:01 pm, Josh Flanagan <joshuaflana...@gmail.com> wrote:
> I don't think you want to access instances via the Model property of
> the container - that is more for introspection/diagnostics scenarios.
> Instances should be retrieved using the standard GetInstance()
> methods.
>
> Create a class that takes in an array of IAutoMapperConfiguration in
> its constructor. Give it a method (Configure) which loops over each
> injected instance and calls Configure.
> (pseudo code):
> class AutoMapperConfigurer{
> public AutoMapperConfigurer(IAutoMapperConfiguration mappers){
> _mappers = mappers;
>
> }
>
> public void Configure(){
> _mappers.Each(x => x.Configure());
>
> }
> }
>
> Then in your bootstrapper, after you have initialized the container:
> container.GetInstance<AutoMapperConfigurer>().Configure();
>
> In your bootstrapper, you
>