﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - Crosslight - How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Thu, 07 Aug 2014 17:32:15 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Well, I believe my question regarding the&amp;nbsp;&lt;b&gt;EntityContext&amp;nbsp;&lt;/b&gt;is for the&amp;nbsp;&lt;b&gt;BasicAuthHttpModule&amp;nbsp;&lt;/b&gt;dirently instantiating the&amp;nbsp;&lt;b&gt;IdentityContext()&lt;/b&gt;&amp;nbsp;object. In which case we can't see any method to pass in the CompanyCode into the request before it even authenticates the user. Sure the controllers can be manipulated since these things do accept parameters, but that's not the case for the BasicAuthHttpModule. Or we could be wrong.&lt;/p&gt;&lt;p&gt;&lt;br&gt;The only way I see how to pass a company code to that module is to concatenate it with the password, assuming it is being submitted in plain text (not already hashed). Then, parse that password to get the company code from there and create a connection string, before the&amp;nbsp;&lt;b&gt;AuthenticateWebApiUser(string credentials)&amp;nbsp;&lt;/b&gt;even retrieves the&amp;nbsp;&lt;b&gt;UserManager&amp;nbsp;&lt;/b&gt;from the IdentityContext using the default connection.&lt;/p&gt;&lt;p&gt;&lt;br&gt;Does that make any sense? Or is there another way of doing it? Our enterprise application do serve multiple clients, so please bear with us in this matter. We are thinking of creating separate IIS Virtual Applications for each client to get rid of this predicament, but that's gonna cause huge deployment resources.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;Well, let us know what you think. We do value your advice, so please do keep 'em coming. As always, thanks!&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Thu, 07 Aug 2014 03:35:21 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;Q&lt;/strong&gt; : ...how does Crosslight actually use the &lt;strong&gt;BasicAuthHttpModule&lt;/strong&gt; module? By that, I mean how are the passwords being hashed? Is it the ASP.NET identity that is doing the hashing?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;A&lt;/strong&gt; : Yes, it is using ASP.NET identity to do the hashing.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;Q&lt;/strong&gt; : how do you pass a CompanyCode to BasicAuthHttpModule in order to dynamically create a valid connection string to the IdentityContext() within that module? Is there a way to do that with the existing implementation?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;A&lt;/strong&gt; : You can create a valid connection string in the controller-action method that will handle the HTTP request.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;[HttpGet]
public virtual HttpResponseMessage Login(string userName, string password, string companyCode)
{
    ...
    //you can use the company code here to initialize the EntityContext based on CompanyCode
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Hope this help.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Tue, 05 Aug 2014 01:11:28 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hi Yudi,&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;&lt;br&gt;As always, you do provide great help. Now that we have established connection with identity services, how does crosslight actually use the &lt;/span&gt;&lt;b style="font-size: 10pt;"&gt;BasicAuthHttpModule &lt;/b&gt;&lt;span style="font-size: 10pt;"&gt;module? By that, I mean how are the passwords being hashed? Is it the ASP.NET identity that is doing the hashing? If not, how do we customize PasswordHash in order to use our own, since our user accounts were created using a different hash algorithm.&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;In addition, how do you pass a &lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;CompanyCode &lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;to &lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;BasicAuthHttpModule &lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;in order to dynamically create a valid connection string to the &lt;/span&gt;&lt;b style="font-size: 10pt;"&gt;IdentityContext()&lt;/b&gt;&lt;span style="font-size: 10pt;"&gt; within that module? Is there a way to do that with the existing implementation?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;&lt;br&gt;Many thanks!&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Mon, 04 Aug 2014 08:17:32 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Apologize for the delay in sending this.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;For such scenario, we can separate the tasks into two parts.&lt;/span&gt;&lt;/p&gt;&lt;ol style="color: #1f497d;"&gt;&lt;li&gt;Modify the server side (WebAPI)&lt;/li&gt;&lt;li&gt;Modify the client side (Crosslight part)&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;Modify the server side (WebAPI)&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;In this part, we are going to modify the WebAPI so it will understand how to process HTTP requests from the client with custom routing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;First we will need to modify the Web API routes in WebApiConfig.cs file. We can start by modifying following code:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public static void Register(HttpConfiguration config)
{
    // Web API configuration and services

    // Web API routes
    config.MapHttpAttributeRoutes();

    config.Routes.MapHttpRoute(
        name: "DataApi",
        routeTemplate: "data/{controller}/{action}"
    );

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;into:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public static void Register(HttpConfiguration config)
{
	// Web API configuration and services

	// Web API routes
	config.MapHttpAttributeRoutes();

	config.Routes.MapHttpRoute(
		name: "DataApi",
		routeTemplate: "data/{controller}/{action}/{companyCode}",
		defaults: new { companyCode = RouteParameter.Optional }
	);

	config.Routes.MapHttpRoute(
		name: "DefaultApi",
		routeTemplate: "api/{controller}/{companyCode}/{id}",
		defaults: new { id = RouteParameter.Optional, companyCode = RouteParameter.Optional }
	);
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Next, we will need to add a controller-action method that will handles the HTTP request with following pattern: data/{controller}/{action}/{companyCode}.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;We can use the Login action-method for reference.&lt;br&gt;The function can be something like following:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;[HttpGet]
public virtual HttpResponseMessage Login(string userName, string password, string companyCode)
{
	...
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Now, we have done the first part. When there is HTTP request such as: http://sitename.com/data/identity/Login/GlobalTechInc?userName=JohnDoe&amp;amp;password=p@55w0rd, the server (WebAPI project) knows which action-method that should handle the request.&lt;/span&gt;&lt;/p&gt;&lt;br&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;&lt;strong&gt;Modify the client side (Crosslight part)&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;In this part, we need to modify the rest request in order to be able to access the above web service.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Let’s start by modifying login process. Using AppFramework, the login process uses UserService and UserRepository to connect to the IdentityController (WebApi).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Following snippet code is the method which performs login process using user account asynchronously in UserRepository.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public async Task&amp;lt;bool&amp;gt; LoginAsync(IAccount account)
{
	var request = this.InitializeLoginAsyncRequest(account);
	var response = await this.ExecuteAsync(request);

	return this.OnLoginAsyncCompleted(response);
}
&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;We need to modify the request by overriding InitializeLoginAsyncRequest (to add companyCode parameter). Create a new class, for example: CustomUserRepository; inherit UserRepository class; and override InitializeLoginAsyncRequest method. These can be done in AppService.cs file under Infrastructure folder of Core project.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;These changes are shown in the following snippet code.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;public class CustomUserRepository : UserRepository
{
    protected override IRestRequest InitializeLoginAsyncRequest(IAccount account)
    {
        RestRequest request = new RestRequest(this.LoginActionName + "/" + this.GetCompanyCode(), HttpMethod.GET);
        request.RequestFormat = RequestDataFormat.Json;
        request.AddParameter("username", account.Username);
        request.AddParameter("password", account.GetProperty(Account.PasswordHash));

        // ensure no account is associated in login request
        this.RestClient.Account = null;

        return request;
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Please note that we need to repeat the steps above for the other method in the repository class.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Last, modify the registered data repositories by replacing the default UserRepository registration with the new one, CustomUserRepository.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Hope this help.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Mon, 04 Aug 2014 00:28:32 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;blockquote&gt;&lt;p&gt;Hey guys, any thoughts on this?&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Thanks!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Hey Guys! Awesome release on Update 3. I understand you might be very busy, and deserves quite a break after that great new update release BUT I do hope you find time to give us some advice regarding this issue. Now that we are really trying take advantage of Crosslight feature, we would really appreciate you taking time helping us out with this one. Here are few insights that we have:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: 10pt;"&gt;We are really new with MVC and Web API, and considering going for custom routing (e.g. data/{controller}/{companyCode}/) to our URL, instead of Crosslight's pre-defined route. Question is... is that a good way to go, considering we don't want to screw any of the existing services with Crosslight. That said, we are really aiming for less customization as possible to really fit in with Crosslight's services.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt;"&gt;We understand you have opened souces to your Intersoft.AppFramework, is that an indication that we can implement our own logic with the existing interfaces such as&amp;nbsp;&lt;span style="font-family: monospace; font-size: 12px; line-height: 18px; white-space: pre; background-color: rgb(255, 255, 255);"&gt;IUserService, &lt;/span&gt;&lt;span style="font-family: monospace; font-size: 12px; line-height: 18px; white-space: pre; background-color: rgb(255, 255, 255);"&gt;IUserRepository, and IAccountService &lt;/span&gt;to name a few? We're guessing it is, but the answer still lies upon you. If the case is true, can we do constructor injection on these implementations, such that we can provide a custom parameter (e.g. ICompanyService) to pass the companyCode property?&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;BUT, we're looking forward to getting a response from you. Your feedback regarding this matter is really appreciated. As always, many thanks!&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Thu, 31 Jul 2014 18:55:31 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hey guys, any thoughts on this?&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Thanks!&lt;/p&gt;</description></item><item><title>How to Use Crosslight v2 Business Template with Multiple Databases?</title><link>http://www.intersoftsolutions.com/Community/Crosslight/How-to-Use-Crosslight-v2-Business-Template-with-Multiple-Databases/</link><pubDate>Wed, 30 Jul 2014 22:34:18 GMT</pubDate><dc:creator>dfugaban@silentpartnersoft.com</dc:creator><description>&lt;p&gt;Hey Guys,&lt;/p&gt;&lt;p&gt;We are fairly new to Web API, and based on Crosslight's business template, we have no idea how we can configure this template to connect to a database depending on which client is requesting access. We have an existing WCF web service, wherein each method has a parameter called CompanyCode. Ideally we should be able to pass in a CompanyCode, and based on this CompanyCode the connection string will be dynamically created and passed on to the constructor of the database context or entity at runtime. But the same idea doesn't fit with the account and authentication services, nor any other services from the business template because it is tightly-coupled to a single database, initially.&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;So, kindly advise how we can extend the business template and services to allow an application to connect to a specific database at runtime. We don't want to move astray from Crosslight templates by creating our own services... so please shed some light to our concern and we are hoping you could provide a sample project as a solution.&lt;/span&gt;&lt;/p&gt;</description></item></channel></rss>