I have a class called UsersOnlineModule that is being created from an IHttpModul. Within this class I would like to have two properties injected, I'm using Simple Injector for this.
public class UsersOnlineModule
{
public ITenantStore tenantStore;
public ICacheManager cm;
I'm calling this class from an IHttpModule:
Modules.UsersOnline.UsersOnlineModule usersOnlineModule =
new Modules.UsersOnline.UsersOnlineModule();
usersOnlineModule.TrackUser(app.Context);
However my IHttpModule does not know about the cache manager or tenantStore. I can solve this by getting the objects from the container, however I would prefer not to create a reference to Simple Injector. Is there any other nice option to resolve these two properties without creating references to my container?
-- Update
I modified the example as follows:
class ImportAttributePropertySelectionBehavior : IPropertySelectionBehavior
{
public bool SelectProperty(Type serviceType, PropertyInfo propertyInfo)
{
return typeof(IHttpModule).IsAssignableFrom(serviceType) &&
propertyInfo.GetCustomAttributes<ImportAttribute>().Any();
}
}
private static void RegisterHttpModules(Container container)
{
var httpModules =
from assembly in BuildManager.GetReferencedAssemblies().Cast<Assembly>()
where !assembly.IsDynamic
where !assembly.GlobalAssemblyCache
from type in assembly.GetExportedTypes()
where type.IsSubclassOf(typeof(IHttpModule))
select type;
httpModules.ToList().ForEach(container.Register);
}
but it's not returning any of my httpmodules.