Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it ok to add static reference to a service layer in Global.asax?
    text
    copied!<p>I am assessing the <a href="http://nuget.org/packages/Highway.Data.EntityFramework.Unity/3.0.3.2" rel="nofollow">Highway.Data.EntityFramework.Unity</a> package in the context of a single project ASP.NET Web Forms application.</p> <p>I want easy access to my service layer. Here is the relevant part of Global:</p> <pre><code>public class Global : HttpApplication { private static readonly IUnityContainer Container = new UnityContainer(); public static IEmployeeService Service { get; private set; } protected void Application_Start(object sender, EventArgs e) { Container.BuildHighway(); Container.RegisterType&lt;IMappingConfiguration, EntityMapping&gt;(); Container.RegisterType&lt;IEmployeeService, EmployeeService&gt;( new PerRequestLifetimeManager()); Container.RegisterType&lt;IRepository, Repository&gt;( new PerRequestLifetimeManager()); Container.RegisterType&lt;IDataContext, DataContext&gt;( new PerRequestLifetimeManager(), new InjectionConstructor("DataContext", new EntityMapping())); Service = Container.Resolve&lt;IEmployeeService&gt;(); } } </code></pre> <p>In my client, I can access like this:</p> <pre><code>this.Employees.DataSource = this.service.GetEmployees(); this.Employees.DataBind(); </code></pre> <p>Works fine but I haven't taken this approach before and just because it appears to be ok... well, is it? If not, what do I do?</p> <p>[Editited] For requested clarity.</p> <p>Service:</p> <pre><code>public class EmployeeService : IEmployeeService { private readonly IRepository repository; public EmployeeService(IRepository repository) { this.repository = repository; } public IEnumerable&lt;Employee&gt; GetEmployees() { return this.repository.Find( new AllEmployeesQuery()) .ToList() .Select(ObjectMapper.Map&lt;EmployeeEntity, Employee&gt;); } } </code></pre> <p>AllEmployeesQuery is a specification. Business object is mapped to EF entity by AutoMapper and vice-versa.</p> <p>Thanks, Richard</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload