Here's my situation:
* I have a large set of `abstract class Entity` implementations.
* For each implementation of `Entity` I need a
`EntityService<TEntity>` wired in automatically.
* `EntityService<TEntity>` also implements `IService` which is the
common interface for a large chunk of services in my apps
* There are already several other unrelated `IService`
implementations being registered
* Now I need all the `EntityService<TEntity>` to be included when I
resolve an `IEnumerable<IService>`
Is that possible to do in the latest downloadable bits?
Here's what I have so far... which doesn't work
b.RegisterAssemblyTypes(typeof(Entity).Assembly)
.AssignableTo<Entity>()
.AsClosedTypesOf(typeof(EntityService<>))
.As<IService>()
.SingleInstance();
I know that I can do a manual registration by constructing types
manually via Reflection and Type.MakeGenericType but that seems
elaborate. I'm thinking that there must be a proper Autofac-way of
doing this.
..
Thanks for any help!
Do you have types in your assembly that close the EntityService<> open
generic type?
e.g.
public class FooService : EntityService<Foo>
{
}
The AsClosedTypesOf method does not create a closing type for you. You
will need to ensure that closing types exist for the registration to
work.
You should also remove the AssignableTo method call because the
closing types you are looking for will not be assignable to Entity.
Cheers,
Alex.
I'm thinking that Autofac would let me generate types on the fly. I'm
being a little too optimistic there it seems. Autofac will only create
closed generic types as they're requested so even if I activates an
IEnumerable<IService> it won't suddenly try to close all generic types
that's assignable to IService, right?
On Apr 11, 7:51 pm, Alex Meyer-Gleaves <alex.meyerglea...@gmail.com>
wrote:
--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.