How to embed ninject in a static class with extension functions

I got some static classes with extension methods that add “business logic” to objects using the repository template.

Now sometimes I need to create a new one IRepositoryin these extension functions.

I am currently working on this, accessing my Ninject core through an object that I am expanding, but it is really ugly:

public static IEnumerable<ISomething> GetSomethings(this IEntity entity)
{
    using (var dataContext = entity.kernel.Get<IDataContext>())
        return dataContext.Repository<ISomething>().ToList();
}

I could also create a static constructor by accessing the Ninject core in some way from the factory, is there already an infrastructure for this in Ninject 2?

Does anyone know a better solution? Does anyone have any comments on this for implementing business logic.

+5
1

, . :

  • - ​​ ( Injection Dependency). , Entity ( )

  • , , ,

, ( , ) - , Ninject . , (, MVC WCF), -, . , WCF http://github.com/ninject/ninject.extensions.wcf/blob/master/source/Ninject.Extensions.Wcf/NinjectServiceHost.cs

, , , Entity - ( DDD).

, ( Ninject, )

+4

All Articles