I have 3 tire architecture application. In my Data Access is like below:
ICategoryRepository.cs
Code
public interface ICategoryRepository { void Add(Category category); }CategoryRepository.cs
Code
internal class CategoryRepository :ICategoryRepository { void ICategoryRepository.Add(Category category) { // Dbcontext goes here } }And I have a Autofac model to register the above classes in autofac container is:
C#
public class RepositoryModule : Module { protected override void Load(ContainerBuilder builder) { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); builder.RegisterAssemblyTypes(assembly).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces(); base.Load(builder); } }And I have a service layer as below: ICategoryService.cs
Code
public interface ICategoryService { void Add(Category category); }CategoryService.cs
C#
internal class CategoryService : ICategoryService { private ICategoryRepository _categoryRepository; public CategoryService(ICategoryRepository cateoryRepository) { _categoryRespoitory = categoryRepository; } void ICategoryService.Add(Category category) { _categoryRepository.Add(category); } }Similarly, I have a module to register the above class in container as,
C#
public class ServiceModule : Autofac.Module { protected override void Load(ContainerBuilder builder) { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); builder.RegisterAssemblyTypes(assembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerLifetimeScope(); } }And in my Web, Global.asax.cs:
C#
public class Global : System.Web.HttpApplication, IContainerProviderAccessor { static IContainerProvider _containerProvider; public IContainerProvider ContainerProvider { get { return _containerProvider; } } void Application_Start(object sender, EventArgs e) { var builder = new ContainerBuilder(); var assembly = System.Reflection.Assembly.GetExecutingAssembly(); _containerProvider = new ContainerProvider(builder.Build()); } }Here my question is, how can call the service and DataAccess module from the web.[I don't have the data access reference in my web, but I have reference of service module in my web]
Thanks in advance.
Answers
Know the answer? Post it. Somebody with the same question will find it here.