aspnetboilerplate: plugin with own dbcontext and UI - aspnetboilerplate

How to create a separate dbcontext and ui for each plugin created for aspnetboilerplate?
https://aspnetboilerplate.com/Pages/Documents/Plugin

Related

aspnetboilerplate: How to implement dynamic module management?

How to implement dynamic module(plugin) installation/deletion in aspnetboilerplate?
suppose I create a separate class library project to implement versioning of project module
e.g. for a billing module(plugin) I create a separate class library project & a separate dbcontext within that and create multiple versions of that dll
for fine grained updates to the aspnetboilerplate application I want ability to deploy the dll dynamically,
I mean when I build new version of billing module(say v2) I want to deploy that dll only instead of deploying the whole aspnetboilerplate project.
how do I achieve this?
My requirement is to implement plugin kind of architecture in aspnetboilerplate.
plugin can be dynamically added or removed or upgraded to newer version through UI
-nitin

Dispose DBContext when request completes when using MEF for dependency injection

I am currently working on a Web API project that uses MEF for dependency injection.
In other projects I have used Unity and its PerRequestLifetimeManager to dispose the DBContext when the request completes.
However, I could not find a way to perform the same task with MEF.
So my question is - how can I dispose the DBContext when the request completes when using MEF for dependency injection?

Where should i put my ef model files

I am working on an asp.net core mvc 2.0 web application.
This application works with an sql server database and entity framework core.
I want to create a console project for doing some batch stuff at night. This project should access the same database than the web project.
So i decided to create a third common project (library) which will contains models classes, db context and migrations.
The 2 project will reference this common project.
When i try to run "dotnet ef" commands in the terminal, in the common project subfolder, i get an error saying me this project should be startup project. But this is a shared library ...
EF Core differs from EF in that the context is designed to be instantiated via a dependency injection container. In other words, it relies on a DbContextOptions instance being injected that tells it among other things what type of database connection to use and how to connect. Since this injection only occurs inside projects that actually run (i.e. not a class library), the EF command-line tools only work by default with "startup projects", i.e. projects that can actually be started.
To enable migrating against a class library, EF Core provides IDesignTimeDbContextFactory. The EF commands will look for an implementation of this interface, and if it exists, use that factory to create the context it needs. As a result, you simply need to create an implementation in your class library.
public class MyContextFactory : IDesignTimeDbContextFactory<MyContext>
{
public MyContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<MyContext>();
optionsBuilder.UseSqlServer("[connection string here]");
return new MyContext(optionsBuilder.Options);
}
}
Yes, this means you need to hard-code your connection string, but importantly this is not environment-specific. More appropriately, the only environment you should be migrating in is development, so you don't need it to be environment-specific.
Documentation

Can EntityObject be used to directly generate a view for various scaffolds?

When I add a strongly typed view I see my Entities listed in the Model class dropdown. But, if I select an entity and Scaffold, say List, I get a runtime error of object reference not set to an instance of an object.
In past projects I created a Service layer that called LINQ using CRUD. Then I consumed this service in my Controller and manually created the Views from the resulting service classes. It would be a lot easier if MVC just did all that for me.
Is it possible to directly create scaffold views from concrete classes inheriting EntityObject?
Simple answer : Yes.
I just tried the following test case...
New Project
Create EDMX
Build
Add Controller (With Read/Write actions and views using entity framework
pick Model class and context (the thing normally suffixed with 'entities'
click add
run - it works
EDIT: added MVC Scaffolding too...
open package manager
Install-Package MvcScaffolding
Add Controller (MVC Scaffolding controller With read/write actions & views using EF COde)
Build and Run : Also works.

IRepository, IService, Unity in an ASP.NET MVC Application, reference question

I'm new to Unity, but this question is more generic to IoC, and I’m pretty new to implementing IoC as a whole. I have VS2010 solution with this project structure (simplified slightly):
Business Objects – Folder
DomainModel (Class Lib prj.) – Entity Framework 2 POCO entities
Data Layer – Folder
DataAccess (Class Lib prj.) – EF2 EDMX
Repository (Class Lib prj.) – IRepository interface & repository concrete implementations
Presentation Layer – folder
WebUI – MVC Project
Service Layer
Service (Class Lib prj.) – IService interface and service (façade pattern) concrete implementations
All project reference the DomainModel project.
Repository references the DataAccess project.
Service Layer references the Repository project.
WebUI references the Service project & the Unity assemblies.
I have Unity configured to inject all my service types correctly in the WebUI (global.asax via a custom UnityControllerFactory.cs). But how do I configure Unity in the service layer to inject the repository objects?
I DON’T want to reference the Repository project from the WebUI to ensure during development no one shortcuts and bypass the Service layer.
Couple Ideas I have (not sure if it will solve it):
Move the IRepository Interfaces into the DomainModel and add the Unity.RegisterType<> calls for the IRepository
Set up Unity configuration in the Web.config
Any direction would be greatly appreciated, specifically to how to configure Unity for the service layer / Repository, but also in general about the project.
Add a bootstrapper of some sort in the Service project. Then reference the bootstrapper in the WebUI.
One way to do this would be to write a small Unity extension. Something like this:
public class ServiceLayerBootstrap : UnityContainerExtension
{
protected override void Initialize()
{
Container.RegisterType<IRepository, WhateverRepositoryImplementation>();
// etc.
}
}
Then, in the web project where you create the container and initialize it, do this:
var container = new UnityContainer()
.AddNewExtension<ServiceLayerBootstrap>();

Resources