I've read the ABP documentation.
Here is my solution architecture for my new project based on the ABP Framework.
First of all, I want to ask if there is anything wrong with this design?
I've registered all my app services to IocManager in my Holitera.ApplicationModule.
So now I can call my app services from MVC controllers. RegionAppService is my new AppService here.
Here is the registration:
And my RegionAppService class:
public class RegionAppService : AsyncCrudAppService<Region, RegionDto,int>, IRegionAppService
{
private readonly IRepository<Region> _regionRepository;
public RegionAppService(IRepository<Region> regionRepository) :
base(regionRepository)
{
CreatePermissionName = "CreateRegionPermission";
_regionRepository = regionRepository;
}
}
Now I want to create a CRUD Razor page like the Roles view in the default template. But I couldn't register my custom RegionAppService to the JavaScript proxy services.
Do I need a dynamic Web API module to do that? Is that necessary? If it is, then how are Role, User, Customer, Account services registered to the dynamic JS proxy? I couldn't find the configuration for that. As much as I know there is no configuration for dynamic Web API module in the default MVC template? So I don't have an API module yet.
I'm going to need a dynamic JavaScript module later, but not now. First, I just want to handle this.
And by the way, what is the difference between dynamic AJAX call methods and dynamic Web API module? Are they same or if not, how?
Thanks :)
anything wrong with this design?
Entity and DomainService go in Core project. Dto and AppService go in Application project.
You can read about NLayer Architecture.
It's how the other services are discovered, and the right approach.
Do i need dynamic web api module to do that? Is that neccessary?
No.
how are Role, User, Customer, Account services are registered to dynamic js proxy? I couldn't find the configuration for that. As much as i know there is no configuration for dynamic api module in default mvc template?
It's done in YourProjectNameWebCoreModule. You can create controllers for additional assemblies:
Configuration.Modules.AbpAspNetCore()
.CreateControllersForAppServices(
typeof(RegionAppService).GetAssembly()
);
Related
Good morning.
I am a bit confused about these two repositories(graphql-dotnet/graphql-dotnet/ and graphql-dotnet/server/).
https://github.com/graphql-dotnet/graphql-dotnet/ and
https://github.com/graphql-dotnet/server
They are both under the same organization and there is some overlap of contributors, but I'm a bit lost about deciding which one to use.
I would like to build a dotnet 5 application that hosts a graphql endpoint. In a nutshell that is my goal.
I noticed that the graphql-dotnet/server/repository has inbuilt some helpers such as.
serviceCollection
.AddGraphQL((options, provider) =>
{
options.EnableMetrics = HostEnvironment.IsDevelopment();
var logger = provider.GetRequiredService<ILogger<Startup>>();
options.UnhandledExceptionDelegate = ctx => logger.LogError("{Error} occurred", ctx.OriginalException.Message);
})
.AddSystemTextJson()
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = HostEnvironment.IsDevelopment())
.AddWebSockets()
.AddDataLoader()
.AddGraphTypes(typeof(ApplicationSchema))
Which allows my DI to be setup nice and easy. Its counterpart, the graphql-dotnet/graphql-dotnet/ does not.
So my question is "which one should I use exclusivly? Which one is recomended, by secondary goals are to add jwt authentication and finally federation support. But those two are far down the line.
One of my coworkers went ahead and used graphql-dotnet/graphql-dotnet/ and his server application has a lot more configuration than the documentation of graphql-dotnet/server/ so how do I know which one do I use?
Can any one recommend any documentation that highlights the difference between the two of them?
The main graphql-dotnet repo is the "core" library of GraphQL components. The server repo contains ASP.NET specific extensions. It uses the core library. If you use the server project, you are also using the core library.
GraphQL itself can be used with any protocol, it is not required to be used with HTTP or JSON. So the core library does not have any HTTP or ASP.NET dependencies.
If you are using ASP.NET, then the server project is the quickest way to get started. If you want to use Subscriptions, then the server project provides that functionality.
If you don't need subscriptions and if you want a bit more control over how the framework handles the HTTP request, then it would be easier to write your own controller or middleware.
Using JWT authentication is handled by ASP.NET and can be used in either scenario. Federation can also be used in either scenario.
For example, in a ASP.NET page you would do something like
Cache.Add({...}) and access it via Cache["key"]. In this context, Cache is the System.Web.Caching.Cache object.
Is there anyway to do this type of ASP.NET application level caching in web API controllers?
Take a look at the MemoryCache class. From its MSDN documentation:
The MemoryCache class is similar to the ASP.NET Cache class. The
MemoryCache class has many properties and methods for accessing the
cache that will be familiar to you if you have used the ASP.NET Cache
class. The main differences between the Cache and MemoryCache classes
are that the MemoryCache class has been changed to make it usable by
.NET Framework applications that are not ASP.NET applications.
You can create a new instance of a MemoryCache yourself, or you can use the default AppDomain-wide instance via the MemoryCache.Default static property.
Edit: You'll need to add a reference to System.Runtime.Caching.dll if you wish to use this type.
If you are web hosting, why not?
var context = HttpContext.Current;
if (context != null)
{
if (context.Cache["g"] == null)
{
context.Cache["g"] = 9.81;
}
}
But you are adding a dependency on ASP.NET by doing so. Even though ASP.NET Web API has ASP.NET in the name, the Web API is host-agnostic. That is, ASP.NET/IIS is not the only hosting option; the Web API can be self-hosted as well. Something for you to consider before going down that route.
You need to type
HttpContext.Current.Cache
to access the instance. There is no Cache property declared at the Controller level, like on a Page.
Note that the context that hosts the API will need to support caching.
If you are referring to Output caching in ASP.NET Web API. Take a look at this project,
https://github.com/filipw/AspNetWebApi-OutputCache
I'm trying to pass configuration values to bootstrap a single page AngularJs app hosted within an MVC app that utilises WebApi (see below from the Razor view, this is achieved by inheriting a BasePage and dependency injecting a Serializer/FinancialYears service).
<script>
var angularInitConfig = #Html.Raw(Serializier.Serialize(new {
financialYears = FinancialYearsService.GetFinancialYears()
}));
</script>
This works perfectly, however I would really like to be able to extend it to include the routes from my WebApi app to avoid having to configure the endpoints in both the WebApi app AND the AngularJs app individually.
Having poked around in the RouteTable.Routes class I can see that the information I require is available and accessible from within the view, however I've been unable to extract it.
So what I'd ideally like to do is generate a collection of objects as defined below from the RouteTable.Routes class, serialize them and spit them out in the bootstrap config for the AngularJS app to consume.
new {
name = "SomeService",
route = "api/{financialYearId}/someservice",
method = "POST"
}
Does anybody have an idea how to extract this information from RoutesTable.Routes? Is there an easier way to generate the data required?
NB. All WebApi routes are configured explicitly using the Routes attribute as such:
[HttpGet]
[Route("api/{financialYearId}/someservice")]
If you create default template asp.net Mvc or WebAPi using Visual Studio, you will get Help in Folder > Areas\HelpPage...and if you access your application in : Http://yourportapplication/api/Help if project webapi...
then, you can see the code how to get information...just for started what you looking for,....
We are delivering an ASP.NET MVC application built with Sitecore to a client that deploys the application to a multi site/tenant Sitecore installation.
We make heavy use of ServiceStack as we do on most of our projects, but have run into an issue now. Another application in the Sitecore setup is also using ServiceStack. This causes the error:
[InvalidDataException: AppHostBase.Instance has already been set]
Which makes perfect sense really, because all files for all the applications in the Sitecore installation is in the same physical folder on disk. Meaning we share DLL's and everything.
So this other project initializes before ours and when we then try to register our services we get the above error.
Is there any way I can work around this? Can I somehow register my services on the already existing AppHostBase.Instance?
Two things that might be worth noting:
We do not have any influence on the setup of the Sitecore environment.
We can work together with the other team using ServiceStack if something has to be done in both projects.
Preferably you would tell ServiceStack all the assemblies with Services you want registered in your AppHost constructor, e.g:
public class AppHost : AppHostBase
{
//Tell ServiceStack the name of your app and which assemblies to scan for services
public AppHost() : base("Hello ServiceStack!",
typeof(ServicesFromDll1).Assembly,
typeof(ServicesFromDll2).Assembly
/*, etc */) {}
public override void Configure(Container container) {}
}
But you can dynamically Register Services outside of ServiceStack with:
HostContext.ServiceController.RegisterService(typeof(MyService));
Or register all Services in an Assembly with:
HostContext.ServiceController.
RegisterServicesInAssembly(typeof(MyService).Assembly);
I need to call my service with the standard url restful:
http://localhost/users : getall user
http://localhost/user/1 : get user with id 1
But the standard URLs in WCF looks like:
http://localhost/Userservice.svc/getallusers
I would like to change this, but since I use the Spring.net framework in my service WCF, I must create my Custom ServiceHostFactory MyServiceHostFactory
Spring is used in my project to do the injection dependencies and thus nothing new object
I try to add a route in global.asax
RouteTable.Routes.Add(new ServiceRoute("Users", new MyServiceHostFactory(), typeof(UserService)));
But when i call my service http://localhost/users
, I receive the error: ServiceHost only supports class service types
I don't understand the problem and is it possible to resolve this problem ?
Thanks for your help